[FFmpeg-devel] [PATCH] avocdec/hevcdec: set SEI derived AVCodecContext fields as soon as they are parsed

James Almer jamrial at gmail.com
Thu Sep 17 03:36:09 EEST 2020


export_stream_params() may not be called in some scenarios, for example leaving
both the AVCodecContext and subsequent output frames with the color_trc value
taken from the VUI instead of the Alternative Transfer Characteristics SEI.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/hevcdec.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index c1de75abe1..2f1e469c94 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -369,12 +369,6 @@ static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
     if (num != 0 && den != 0)
         av_reduce(&avctx->framerate.den, &avctx->framerate.num,
                   num, den, 1 << 30);
-
-    if (s->sei.alternative_transfer.present &&
-        av_color_transfer_name(s->sei.alternative_transfer.preferred_transfer_characteristics) &&
-        s->sei.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
-        avctx->color_trc = s->sei.alternative_transfer.preferred_transfer_characteristics;
-    }
 }
 
 static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
@@ -2806,8 +2800,6 @@ static int set_side_data(HEVCContext *s)
         if (!sd)
             av_buffer_unref(&a53->buf_ref);
         a53->buf_ref = NULL;
-
-        s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
     }
 
     for (int i = 0; i < s->sei.unregistered.nb_buf_ref; i++) {
@@ -2853,6 +2845,22 @@ static int set_side_data(HEVCContext *s)
     return 0;
 }
 
+static int export_stream_params_from_sei(HEVCContext *s)
+{
+    AVCodecContext *avctx = s->avctx;
+
+    if (s->sei.a53_caption.buf_ref)
+        s->avctx->properties |= FF_CODEC_PROPERTY_CLOSED_CAPTIONS;
+
+    if (s->sei.alternative_transfer.present &&
+        av_color_transfer_name(s->sei.alternative_transfer.preferred_transfer_characteristics) &&
+        s->sei.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
+        avctx->color_trc = s->sei.alternative_transfer.preferred_transfer_characteristics;
+    }
+
+    return 0;
+}
+
 static int hevc_frame_start(HEVCContext *s)
 {
     HEVCLocalContext *lc = s->HEVClc;
@@ -2974,6 +2982,9 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
                 goto fail;
         }
         ret = ff_hevc_decode_nal_sei(gb, s->avctx, &s->sei, &s->ps, s->nal_unit_type);
+        if (ret < 0)
+            goto fail;
+        ret = export_stream_params_from_sei(s);
         if (ret < 0)
             goto fail;
         break;
-- 
2.27.0



More information about the ffmpeg-devel mailing list