Skip to content

Commit

Permalink
avformat: validate dovi config in muxers
Browse files Browse the repository at this point in the history
  • Loading branch information
gnattu committed Oct 21, 2024
1 parent 845992e commit f638f3f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ Index: FFmpeg/libavformat/movenc.c
===================================================================
--- FFmpeg.orig/libavformat/movenc.c
+++ FFmpeg/libavformat/movenc.c
@@ -8124,6 +8124,7 @@ static const AVCodecTag codec_mp4_tags[]
@@ -8128,6 +8128,7 @@ static const AVCodecTag codec_mp4_tags[]
{ AV_CODEC_ID_HEVC, MKTAG('h', 'e', 'v', '1') },
{ AV_CODEC_ID_HEVC, MKTAG('h', 'v', 'c', '1') },
{ AV_CODEC_ID_HEVC, MKTAG('d', 'v', 'h', '1') },
+ { AV_CODEC_ID_HEVC, MKTAG('d', 'v', 'h', 'e') },
{ AV_CODEC_ID_VVC, MKTAG('v', 'v', 'c', '1') },
{ AV_CODEC_ID_VVC, MKTAG('v', 'v', 'i', '1') },
{ AV_CODEC_ID_EVC, MKTAG('e', 'v', 'c', '1') },
@@ -8137,6 +8138,7 @@ static const AVCodecTag codec_mp4_tags[]
@@ -8141,6 +8142,7 @@ static const AVCodecTag codec_mp4_tags[]
{ AV_CODEC_ID_TSCC2, MKTAG('m', 'p', '4', 'v') },
{ AV_CODEC_ID_VP9, MKTAG('v', 'p', '0', '9') },
{ AV_CODEC_ID_AV1, MKTAG('a', 'v', '0', '1') },
Expand Down Expand Up @@ -117,16 +117,65 @@ Index: FFmpeg/libavformat/mpegtsenc.c
static int get_dvb_stream_type(AVFormatContext *s, AVStream *st)
{
MpegTSWrite *ts = s->priv_data;
@@ -803,7 +850,16 @@ static int mpegts_write_pmt(AVFormatCont
@@ -803,7 +850,65 @@ static int mpegts_write_pmt(AVFormatCont
} else if (stream_type == STREAM_TYPE_VIDEO_VC1) {
put_registration_descriptor(&q, MKTAG('V', 'C', '-', '1'));
} else if (stream_type == STREAM_TYPE_VIDEO_HEVC && s->strict_std_compliance <= FF_COMPLIANCE_NORMAL) {
- put_registration_descriptor(&q, MKTAG('H', 'E', 'V', 'C'));
+ const AVPacketSideData *sd = av_packet_side_data_get(st->codecpar->coded_side_data,
+ st->codecpar->nb_coded_side_data, AV_PKT_DATA_DOVI_CONF);
+ const AVDOVIDecoderConfigurationRecord *dovi = sd ? (const AVDOVIDecoderConfigurationRecord *)sd->data : NULL;
+ int is_dovi_config_valid = dovi != NULL;
+
+ if (dovi && dovi->bl_present_flag && s->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) {
+ if (dovi) {
+ switch (dovi->dv_level) {
+ case 4:
+ case 5:
+ case 7:
+ case 8:
+ if (st->codecpar->codec_id != AV_CODEC_ID_HEVC) {
+ is_dovi_config_valid = 0;
+ }
+ break;
+ default:
+ is_dovi_config_valid = 0;
+ break;
+ }
+
+ switch (dovi->dv_bl_signal_compatibility_id) {
+ case 1:
+ case 6:
+ if (st->codecpar->color_trc != AVCOL_TRC_SMPTE2084 ||
+ st->codecpar->color_primaries != AVCOL_PRI_BT2020 ||
+ st->codecpar->color_space != AVCOL_SPC_BT2020_NCL ||
+ st->codecpar->color_range != AVCOL_RANGE_MPEG ||
+ st->codecpar->format != AV_PIX_FMT_YUV420P10) {
+ is_dovi_config_valid = 0;
+ }
+ break;
+ case 2:
+ // Don't check range or color info for SDR base layer as a lot of them will set to unspecified
+ // And a lot of players assumes unspecified as BT709 in tv range
+ if (st->codecpar->format != AV_PIX_FMT_YUV420P) {
+ is_dovi_config_valid = 0;
+ }
+ break;
+ case 4:
+ if (st->codecpar->color_trc != AVCOL_TRC_ARIB_STD_B67 ||
+ st->codecpar->color_primaries != AVCOL_PRI_BT2020 ||
+ st->codecpar->color_space != AVCOL_SPC_BT2020_NCL ||
+ st->codecpar->color_range != AVCOL_RANGE_MPEG ||
+ st->codecpar->format != AV_PIX_FMT_YUV420P10) {
+ is_dovi_config_valid = 0;
+ }
+ break;
+ default:
+ // others are reserved value, don't check
+ break;
+ }
+ }
+
+ if (dovi && is_dovi_config_valid && dovi->bl_present_flag && s->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) {
+ if (put_dovi_descriptor(s, &q, dovi) < 0)
+ break;
+ } else {
Expand Down
1 change: 1 addition & 0 deletions debian/patches/series
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@
0075-allow-vpl-qsv-to-init-with-the-legacy-msdk-path.patch
0076-alway-set-videotoolboxenc-pixel-buffer-info.patch
0077-add-remove-dovi-hdr10plus-bsf.patch
0077-validate-dovi-config-for-muxers.patch

0 comments on commit f638f3f

Please sign in to comment.