[FFmpeg-cvslog] avcodec/dvbsubdec: Support computing clut only once

Michael Niedermayer git at videolan.org
Mon Mar 29 23:21:28 EEST 2021


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Thu Mar  4 14:22:31 2021 +0100| [7b4510d2a875f666ed6d990f03331a3c60aca53f] | committer: Michael Niedermayer

avcodec/dvbsubdec: Support computing clut only once

This avoids crafted files from consuming excessive resources recomputing the clut after each pixel change

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7b4510d2a875f666ed6d990f03331a3c60aca53f
---

 doc/decoders.texi      | 2 ++
 libavcodec/dvbsubdec.c | 7 ++++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/doc/decoders.texi b/doc/decoders.texi
index 27c6ba4a5d..1a2087d397 100644
--- a/doc/decoders.texi
+++ b/doc/decoders.texi
@@ -293,6 +293,8 @@ Enabled by default.
 @table @option
 @item compute_clut
 @table @option
+ at item -2
+Compute clut once if no matching CLUT is in the stream.
 @item -1
 Compute clut if no matching CLUT is in the stream.
 @item 0
diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index 9bee33e4a2..ec2304bfb9 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -823,7 +823,7 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou
 
             memcpy(rect->data[0], region->pbuf, region->buf_size);
 
-            if ((clut == &default_clut && ctx->compute_clut == -1) || ctx->compute_clut == 1) {
+            if ((clut == &default_clut && ctx->compute_clut < 0) || ctx->compute_clut == 1) {
                 if (!region->has_computed_clut) {
                     compute_default_clut(ctx, region->computed_clut, rect, rect->w, rect->h);
                     region->has_computed_clut = 1;
@@ -979,7 +979,8 @@ static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDis
         }
     }
 
-    region->has_computed_clut = 0;
+    if (ctx->compute_clut != -2)
+        region->has_computed_clut = 0;
 }
 
 static int dvbsub_parse_object_segment(AVCodecContext *avctx,
@@ -1737,7 +1738,7 @@ end:
 #define OFFSET(x) offsetof(DVBSubContext, x)
 static const AVOption options[] = {
     {"compute_edt", "compute end of time using pts or timeout", OFFSET(compute_edt), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DS},
-    {"compute_clut", "compute clut when not available(-1) or always(1) or never(0)", OFFSET(compute_clut), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, DS},
+    {"compute_clut", "compute clut when not available(-1) or only once (-2) or always(1) or never(0)", OFFSET(compute_clut), AV_OPT_TYPE_BOOL, {.i64 = -1}, -2, 1, DS},
     {"dvb_substream", "", OFFSET(substream), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, DS},
     {NULL}
 };



More information about the ffmpeg-cvslog mailing list