diff mbox series

[FFmpeg-devel,02/12] Render only when necessary

Message ID 20220503161328.842587-3-traian.coza@gmail.com
State New
Headers show
Series I added text to bitmap subtitle conversion functionality! | expand

Checks

Context Check Description
yinshiyou/commit_msg_loongarch64 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
yinshiyou/make_loongarch64 fail Make failed
andriy/commit_msg_x86 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_x86 fail Make failed

Commit Message

Traian Coza May 3, 2022, 4:13 p.m. UTC
---
 fftools/ffmpeg.c           | 12 ++++++++++--
 libavfilter/vf_subtitles.c |  1 -
 2 files changed, 10 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 53717d3ebb..dea2aec2ce 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2422,9 +2422,8 @@  static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output,
         goto out;
 
     ist->frames_decoded++;
-    
-    render_avsub_ass(ist, &subtitle);
 
+    int rendered = 0;
     for (i = 0; i < nb_output_streams; i++) {
         OutputStream *ost = output_streams[i];
 
@@ -2432,6 +2431,15 @@  static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output,
             || ost->enc->type != AVMEDIA_TYPE_SUBTITLE)
             continue;
 
+        if (avcodec_descriptor_get(ost->enc_ctx->codec_id)->props & AV_CODEC_PROP_BITMAP_SUB)
+            if (avcodec_descriptor_get(ist->dec_ctx->codec_id)->props & AV_CODEC_PROP_TEXT_SUB)
+                if (!rendered) {
+                    render_avsub_ass(ist, &subtitle);
+                    for (int r = 0; r < subtitle.num_rects; r++)
+                        subtitle.rects[r]->type = SUBTITLE_BITMAP;
+                    rendered = 1;
+                }
+
         do_subtitle_out(output_files[ost->file_index], ost, &subtitle);
     }
 
diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index f751786033..16f9c3fff6 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -307,7 +307,6 @@  void render_avsub_ass(InputStream *ist, AVSubtitle *sub)
                         rect->data[0][y_rect * rect->w + x_rect] = color;
                     }
         }
-        rect->type = SUBTITLE_BITMAP;
 
         ass_free_track(track);
     }