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

Traian Coza traian.coza at gmail.com
Tue May 3 19:13:18 EEST 2022


---
 fftools/ffmpeg.c           | 12 ++++++++++--
 libavfilter/vf_subtitles.c |  1 -
 2 files changed, 10 insertions(+), 3 deletions(-)

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);
     }
-- 
2.34.1



More information about the ffmpeg-devel mailing list