[FFmpeg-devel] [PATCH v2 1/1] libavcodec/h264: always set video signal type fields

Xiaolei Yu dreifachstein at gmail.com
Thu Nov 25 08:16:01 EET 2021


The color range and color description fields when not present
shall be inferred to be LIMITED and UNSPECIFIED respectively.

Relevant info from containers will always be overriden.
This is consistent with the behavior of the hevc decoder.
---
 libavcodec/h264_ps.c                         |  4 +++-
 libavcodec/h264_slice.c                      | 18 +++++++-----------
 tests/ref/fate/flv-demux                     |  2 +-
 tests/ref/fate/h264-dts_5frames              | 10 +++++-----
 tests/ref/fate/matroska-spherical-mono-remux | 14 +++++++-------
 tests/ref/fate/ts-small-demux                |  2 +-
 6 files changed, 24 insertions(+), 26 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) &&
diff --git a/tests/ref/fate/flv-demux b/tests/ref/fate/flv-demux
index 9daee0594e..f95eaba4cc 100644
--- a/tests/ref/fate/flv-demux
+++ b/tests/ref/fate/flv-demux
@@ -603,6 +603,6 @@ packet|codec_type=video|stream_index=0|pts=11612|pts_time=11.612000|dts=11612|dt
 packet|codec_type=video|stream_index=0|pts=11645|pts_time=11.645000|dts=11645|dts_time=11.645000|duration=33|duration_time=0.033000|size=2600|pos=507811|flags=__|data_hash=CRC32:d35f9e6f
 packet|codec_type=audio|stream_index=1|pts=11656|pts_time=11.656000|dts=11656|dts_time=11.656000|duration=46|duration_time=0.046000|size=346|pos=510431|flags=K_|data_hash=CRC32:4e6b44cb
 packet|codec_type=video|stream_index=0|pts=11678|pts_time=11.678000|dts=11678|dts_time=11.678000|duration=33|duration_time=0.033000|size=1190|pos=510794|flags=__|data_hash=CRC32:a0206c90
-stream|index=0|codec_name=h264|profile=77|codec_type=video|codec_tag_string=[0][0][0][0]|codec_tag=0x0000|width=426|height=240|coded_width=426|coded_height=240|closed_captions=0|film_grain=0|has_b_frames=1|sample_aspect_ratio=1:1|display_aspect_ratio=71:40|pix_fmt=yuv420p|level=21|color_range=unknown|color_space=unknown|color_transfer=unknown|color_primaries=unknown|chroma_location=left|field_order=progressive|refs=1|is_avc=true|nal_length_size=4|id=N/A|r_frame_rate=30000/1001|avg_frame_rate=30/1|time_base=1/1000|start_pts=0|start_time=0.000000|duration_ts=N/A|duration=N/A|bit_rate=393929|max_bit_rate=N/A|bits_per_raw_sample=8|nb_frames=N/A|nb_read_frames=N/A|nb_read_packets=351|extradata_hash=CRC32:07b85ca9|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=0|disposition:still_image=0
+stream|index=0|codec_name=h264|profile=77|codec_type=video|codec_tag_string=[0][0][0][0]|codec_tag=0x0000|width=426|height=240|coded_width=426|coded_height=240|closed_captions=0|film_grain=0|has_b_frames=1|sample_aspect_ratio=1:1|display_aspect_ratio=71:40|pix_fmt=yuv420p|level=21|color_range=tv|color_space=unknown|color_transfer=unknown|color_primaries=unknown|chroma_location=left|field_order=progressive|refs=1|is_avc=true|nal_length_size=4|id=N/A|r_frame_rate=30000/1001|avg_frame_rate=30/1|time_base=1/1000|start_pts=0|start_time=0.000000|duration_ts=N/A|duration=N/A|bit_rate=393929|max_bit_rate=N/A|bits_per_raw_sample=8|nb_frames=N/A|nb_read_frames=N/A|nb_read_packets=351|extradata_hash=CRC32:07b85ca9|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=0|disposition:still_image=0
 stream|index=1|codec_name=aac|profile=1|codec_type=audio|codec_tag_string=[0][0][0][0]|codec_tag=0x0000|sample_fmt=fltp|sample_rate=22050|channels=2|channel_layout=stereo|bits_per_sample=0|id=N/A|r_frame_rate=0/0|avg_frame_rate=0/0|time_base=1/1000|start_pts=0|start_time=0.000000|duration_ts=N/A|duration=N/A|bit_rate=67874|max_bit_rate=N/A|bits_per_raw_sample=N/A|nb_frames=N/A|nb_read_frames=N/A|nb_read_packets=252|extradata_hash=CRC32:d039c029|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=0|disposition:still_image=0
 format|filename=Enigma_Principles_of_Lust-part.flv|nb_streams=2|nb_programs=0|format_name=flv|start_time=0.000000|duration=210.209999|size=512000|bit_rate=19485|probe_score=100|tag:hasKeyframes=true|tag:hasMetadata=true|tag:datasize=11970544|tag:hasVideo=true|tag:canSeekToEnd=false|tag:lasttimestamp=210|tag:lastkeyframetimestamp=210|tag:audiosize=1791332|tag:hasAudio=true|tag:audiodelay=0|tag:videosize=10176110|tag:metadatadate=2011-02-27T11:00:33.125000Z|tag:metadatacreator=inlet media FLVTool2 v1.0.6 - http://www.inlet-media.de/flvtool2|tag:hasCuePoints=false
diff --git a/tests/ref/fate/h264-dts_5frames b/tests/ref/fate/h264-dts_5frames
index 8c6e48de55..e1af469629 100644
--- a/tests/ref/fate/h264-dts_5frames
+++ b/tests/ref/fate/h264-dts_5frames
@@ -22,7 +22,7 @@ display_picture_number=0
 interlaced_frame=0
 top_field_first=0
 repeat_pict=0
-color_range=unknown
+color_range=tv
 color_space=unknown
 color_primaries=unknown
 color_transfer=unknown
@@ -52,7 +52,7 @@ display_picture_number=0
 interlaced_frame=0
 top_field_first=0
 repeat_pict=0
-color_range=unknown
+color_range=tv
 color_space=unknown
 color_primaries=unknown
 color_transfer=unknown
@@ -82,7 +82,7 @@ display_picture_number=0
 interlaced_frame=0
 top_field_first=0
 repeat_pict=0
-color_range=unknown
+color_range=tv
 color_space=unknown
 color_primaries=unknown
 color_transfer=unknown
@@ -112,7 +112,7 @@ display_picture_number=0
 interlaced_frame=0
 top_field_first=0
 repeat_pict=0
-color_range=unknown
+color_range=tv
 color_space=unknown
 color_primaries=unknown
 color_transfer=unknown
@@ -142,7 +142,7 @@ display_picture_number=0
 interlaced_frame=0
 top_field_first=0
 repeat_pict=0
-color_range=unknown
+color_range=tv
 color_space=unknown
 color_primaries=unknown
 color_transfer=unknown
diff --git a/tests/ref/fate/matroska-spherical-mono-remux b/tests/ref/fate/matroska-spherical-mono-remux
index 24d4413a87..bcdc0df8fa 100644
--- a/tests/ref/fate/matroska-spherical-mono-remux
+++ b/tests/ref/fate/matroska-spherical-mono-remux
@@ -1,5 +1,5 @@
-9176856edc1ff2b401e323f422fd8e78 *tests/data/fate/matroska-spherical-mono-remux.matroska
-161583 tests/data/fate/matroska-spherical-mono-remux.matroska
+100bc9e43b751990f6053cf9062ab962 *tests/data/fate/matroska-spherical-mono-remux.matroska
+161587 tests/data/fate/matroska-spherical-mono-remux.matroska
 #extradata 0:       43, 0x2b0e0d7b
 #extradata 1:       43, 0x2b0e0d7b
 #tb 0: 1/1000
@@ -17,7 +17,7 @@
 0,        -40,        160,       40,     1103, 0x082a059f, F=0x0
 1,        -40,        160,       40,     1103, 0x082a059f, F=0x0
 [STREAM]
-color_range=unknown
+color_range=tv
 color_space=unknown
 color_transfer=unknown
 color_primaries=unknown
@@ -41,10 +41,10 @@ roll=15
 [/SIDE_DATA]
 [/STREAM]
 [STREAM]
-color_range=pc
-color_space=bt2020c
-color_transfer=smpte170m
-color_primaries=bt709
+color_range=tv
+color_space=unknown
+color_transfer=unknown
+color_primaries=unknown
 DISPOSITION:default=0
 DISPOSITION:forced=0
 [SIDE_DATA]
diff --git a/tests/ref/fate/ts-small-demux b/tests/ref/fate/ts-small-demux
index 264d878d5b..dd0f25b8cf 100644
--- a/tests/ref/fate/ts-small-demux
+++ b/tests/ref/fate/ts-small-demux
@@ -145,5 +145,5 @@ packet|codec_type=video|stream_index=0|pts=552000|pts_time=6.133333|dts=552000|d
 packet|codec_type=video|stream_index=0|pts=558000|pts_time=6.200000|dts=558000|dts_time=6.200000|duration=6000|duration_time=0.066667|size=16|pos=15792|flags=__side_data|side_data_type=MPEGTS Stream ID|id=224
 |data_hash=CRC32:27b943ef
 packet|codec_type=video|stream_index=0|pts=564000|pts_time=6.266667|dts=564000|dts_time=6.266667|duration=6000|duration_time=0.066667|size=16|pos=16356|flags=__|data_hash=CRC32:f7116111
-stream|index=0|codec_name=h264|profile=578|codec_type=video|codec_tag_string=[27][0][0][0]|codec_tag=0x001b|width=82|height=144|coded_width=82|coded_height=144|closed_captions=0|film_grain=0|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=41:72|pix_fmt=yuv420p|level=10|color_range=unknown|color_space=unknown|color_transfer=unknown|color_primaries=unknown|chroma_location=left|field_order=progressive|refs=1|is_avc=false|nal_length_size=0|id=0x100|r_frame_rate=15/1|avg_frame_rate=15/1|time_base=1/90000|start_pts=126000|start_time=1.400000|duration_ts=444000|duration=4.933333|bit_rate=N/A|max_bit_rate=N/A|bits_per_raw_sample=8|nb_frames=N/A|nb_read_frames=N/A|nb_read_packets=74|extradata_hash=CRC32:e62cae27|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=0|disposition:still_image=0
+stream|index=0|codec_name=h264|profile=578|codec_type=video|codec_tag_string=[27][0][0][0]|codec_tag=0x001b|width=82|height=144|coded_width=82|coded_height=144|closed_captions=0|film_grain=0|has_b_frames=0|sample_aspect_ratio=1:1|display_aspect_ratio=41:72|pix_fmt=yuv420p|level=10|color_range=tv|color_space=unknown|color_transfer=unknown|color_primaries=unknown|chroma_location=left|field_order=progressive|refs=1|is_avc=false|nal_length_size=0|id=0x100|r_frame_rate=15/1|avg_frame_rate=15/1|time_base=1/90000|start_pts=126000|start_time=1.400000|duration_ts=444000|duration=4.933333|bit_rate=N/A|max_bit_rate=N/A|bits_per_raw_sample=8|nb_frames=N/A|nb_read_frames=N/A|nb_read_packets=74|extradata_hash=CRC32:e62cae27|disposition:default=0|disposition:dub=0|disposition:original=0|disposition:comment=0|disposition:lyrics=0|disposition:karaoke=0|disposition:forced=0|disposition:hearing_impaired=0|disposition:visual_impaired=0|disposition:clean_effects=0|disposition:attached_pic=0|disposition:timed_thumbnails=0|disposition:captions=0|disposition:descriptions=0|disposition:metadata=0|disposition:dependent=0|disposition:still_image=0
 format|filename=h264small.ts|nb_streams=1|nb_programs=1|format_name=mpegts|start_time=1.400000|duration=4.933333|size=16544|bit_rate=26828|probe_score=50
-- 
2.33.1



More information about the ffmpeg-devel mailing list