[FFmpeg-devel] [PATCH] libavcodec/h264: always set color description fields

Xiaolei Yu dreifachstein at gmail.com
Wed Nov 24 09:10:53 EET 2021


Color description fields shall be inferred to be UNSPECIFIED if not present.
---
 libavcodec/h264_ps.c    |  4 +++-
 libavcodec/h264_slice.c | 18 +++++++-----------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
index e21c2b56ac..164e6ea0cc 100644
--- a/libavcodec/h264_ps.c
+++ b/libavcodec/h264_ps.c
@@ -378,7 +378,9 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx,
     memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4));
     memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8));
     sps->scaling_matrix_present = 0;
-    sps->colorspace = 2; //AVCOL_SPC_UNSPECIFIED
+    sps->colorspace = AVCOL_SPC_UNSPECIFIED;
+    sps->color_trc = AVCOL_TRC_UNSPECIFIED;
+    sps->color_primaries = AVCOL_PRI_UNSPECIFIED;
 
     if (sps->profile_idc == 100 ||  // High profile
         sps->profile_idc == 110 ||  // High10 profile
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 89ea16a57f..b7f1dfc9ef 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1103,17 +1103,13 @@ static int h264_init_ps(H264Context *h, const H264SliceContext *sl, int first_sl
 
         init_dimensions(h);
 
-        if (sps->video_signal_type_present_flag) {
-            h->avctx->color_range = sps->full_range > 0 ? AVCOL_RANGE_JPEG
-                                                        : AVCOL_RANGE_MPEG;
-            if (sps->colour_description_present_flag) {
-                if (h->avctx->colorspace != sps->colorspace)
-                    needs_reinit = 1;
-                h->avctx->color_primaries = sps->color_primaries;
-                h->avctx->color_trc       = sps->color_trc;
-                h->avctx->colorspace      = sps->colorspace;
-            }
-        }
+        h->avctx->color_range = sps->full_range > 0 ? AVCOL_RANGE_JPEG
+                                                    : AVCOL_RANGE_MPEG;
+        if (h->avctx->colorspace != sps->colorspace)
+            needs_reinit = 1;
+        h->avctx->color_primaries = sps->color_primaries;
+        h->avctx->color_trc       = sps->color_trc;
+        h->avctx->colorspace      = sps->colorspace;
 
         if (h->sei.alternative_transfer.present &&
             av_color_transfer_name(h->sei.alternative_transfer.preferred_transfer_characteristics) &&
-- 
2.33.1


More information about the ffmpeg-devel mailing list