[PATCH 01/17] avformat/mxfenc: Auto-insert h264_mp4toannexb BSF if needed
The mxf and mxf_opatom muxer expect H.264 in Annex B format. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- The check here is taken from mpegtsenc. libavformat/mxfenc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index c36ebef932..d1c4d43a50 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -3174,6 +3174,22 @@ static int mxf_interleave(AVFormatContext *s, AVPacket *pkt, return mxf_interleave_get_packet(s, pkt, flush); } +static int mxf_check_bitstream(AVFormatContext *s, const AVPacket *pkt) +{ + AVStream *const st = s->streams[pkt->stream_index]; + + switch (st->codecpar->codec_id) { + case AV_CODEC_ID_H264: + if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 && + (AV_RB24(pkt->data) != 0x000001 || + (st->codecpar->extradata_size > 0 && + st->codecpar->extradata[0] == 1))) + return ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL); + break; + } + return 1; +} + #define MXF_COMMON_OPTIONS \ { "signal_standard", "Force/set Signal Standard",\ offsetof(MXFContext, signal_standard), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, "signal_standard"},\ @@ -3249,6 +3265,7 @@ const AVOutputFormat ff_mxf_muxer = { .audio_codec = AV_CODEC_ID_PCM_S16LE, .video_codec = AV_CODEC_ID_MPEG2VIDEO, .write_header = mxf_write_header, + .check_bitstream = mxf_check_bitstream, .write_packet = mxf_write_packet, .write_trailer = mxf_write_footer, .deinit = mxf_deinit, @@ -3282,6 +3299,7 @@ const AVOutputFormat ff_mxf_opatom_muxer = { .audio_codec = AV_CODEC_ID_PCM_S16LE, .video_codec = AV_CODEC_ID_DNXHD, .write_header = mxf_write_header, + .check_bitstream = mxf_check_bitstream, .write_packet = mxf_write_packet, .write_trailer = mxf_write_footer, .deinit = mxf_deinit, -- 2.30.2
Also covers writing mastering display metadata. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- tests/fate/mxf.mak | 17 ++++++-- tests/ref/fate/mxf-remux-applehdr10 | 68 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 tests/ref/fate/mxf-remux-applehdr10 diff --git a/tests/fate/mxf.mak b/tests/fate/mxf.mak index 3a1096176f..f96f4a429b 100644 --- a/tests/fate/mxf.mak +++ b/tests/fate/mxf.mak @@ -37,6 +37,11 @@ FATE_MXF_PROBE-$(call ENCDEC2, PRORES, PCM_S24LE, MXF) += fate-mxf-probe-applehd fate-mxf-probe-applehdr10: SRC = $(TARGET_SAMPLES)/mxf/Meridian-Apple_ProResProxy-HDR10.mxf fate-mxf-probe-applehdr10: CMD = run $(PROBE_FORMAT_STREAMS_COMMAND) -i "$(SRC)" | sed -e "s/yuv422p10../yuv422p10/" +# Tests remuxing ProRes as well as writing mastering display metadata. +FATE_MXF_REMUX_PROBE-$(call ALLYES, PRORES_DECODER MXF_MUXER) \ + += fate-mxf-remux-applehdr10 +fate-mxf-remux-applehdr10: CMD = transcode mxf $(TARGET_SAMPLES)/mxf/Meridian-Apple_ProResProxy-HDR10.mxf mxf "-map 0 -c copy" "-c copy -t 0.3" "" "-show_entries format_tags:stream_side_data_list:stream=index,codec_name,codec_tag:stream_tags" + FATE_MXF_REEL_NAME-$(call ENCDEC2, MPEG2VIDEO, PCM_S16LE, MXF) += fate-mxf-reel_name fate-mxf-reel_name: $(SAMPLES)/mxf/Sony-00001.mxf fate-mxf-reel_name: CMD = md5 -y -i $(TARGET_SAMPLES)/mxf/Sony-00001.mxf -c copy -timecode 00:00:00:00 -metadata "reel_name=test_reel" -fflags +bitexact -f mxf @@ -45,7 +50,10 @@ FATE_MXF_USER_COMMENTS-$(call ENCDEC2, MPEG2VIDEO, PCM_S16LE, MXF) += fate-mxf-u fate-mxf-user-comments: $(SAMPLES)/mxf/Sony-00001.mxf fate-mxf-user-comments: CMD = md5 -y -i $(TARGET_SAMPLES)/mxf/Sony-00001.mxf -c copy -metadata "comment_test=value" -fflags +bitexact -f mxf -FATE_MXF_D10_USER_COMMENTS-$(call ALLYES, FILE_PROTOCOL MXF_DEMUXER DVVIDEO_DECODER SCALE_FILTER MPEG2VIDEO_ENCODER MXF_D10_MUXER EXTRACT_EXTRADATA_BSF MPEGVIDEO_PARSER PIPE_PROTOCOL FRAMECRC_MUXER) += fate-mxf-d10-user-comments +FATE_MXF_FFMPEG_FFPROBE-$(call ALLYES, DVVIDEO_DECODER SCALE_FILTER \ + MPEG2VIDEO_ENCODER MXF_D10_MUXER \ + EXTRACT_EXTRADATA_BSF MPEGVIDEO_PARSER) \ + += fate-mxf-d10-user-comments fate-mxf-d10-user-comments: CMD = transcode mxf $(TARGET_SAMPLES)/mxf/Avid-00005.mxf mxf_d10 "-c:v mpeg2video -b:v 30000k -minrate:v 30000k -maxrate:v 30000k -bufsize:v 30000k -rc_init_occupancy 30000k -vf scale=w=1280:h=720 -an -metadata comment_test=value -metadata company_name=FATE-company -metadata product_name=FATE-test -metadata product_version=3.14159 -store_user_comments 1" "-c copy -frames:v 5" "" "-show_entries format_tags" FATE_MXF_OPATOM_USER_COMMENTS-$(call ENCDEC2, MPEG2VIDEO, PCM_S16LE, MXF) += fate-mxf-opatom-user-comments @@ -53,10 +61,13 @@ fate-mxf-opatom-user-comments: $(SAMPLES)/mxf/Sony-00001.mxf fate-mxf-opatom-user-comments: CMD = md5 -y -i $(TARGET_SAMPLES)/mxf/Sony-00001.mxf -an -vcodec copy -metadata "comment_test=value" -fflags +bitexact -f mxf_opatom FATE_MXF-$(CONFIG_MXF_DEMUXER) += $(FATE_MXF) +FATE_MXF_FFMPEG_FFPROBE-$(call ALLYES, FILE_PROTOCOL MXF_DEMUXER \ + PIPE_PROTOCOL FRAMECRC_MUXER) \ + += $(FATE_MXF_REMUX_PROBE-yes) FATE_SAMPLES_AVCONV += $(FATE_MXF-yes) $(FATE_MXF_REEL_NAME-yes) FATE_SAMPLES_AVCONV += $(FATE_MXF_USER_COMMENTS-yes) $(FATE_MXF_OPATOM_USER_COMMENTS-yes) -FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_MXF_D10_USER_COMMENTS-yes) +FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_MXF_FFMPEG_FFPROBE-yes) FATE_SAMPLES_FFPROBE += $(FATE_MXF_PROBE-yes) -fate-mxf: $(FATE_MXF-yes) $(FATE_MXF_PROBE-yes) $(FATE_MXF_REEL_NAME-yes) $(FATE_MXF_USER_COMMENTS-yes) $(FATE_MXF_D10_USER_COMMENTS-yes) $(FATE_MXF_OPATOM_USER_COMMENTS-yes) +fate-mxf: $(FATE_MXF-yes) $(FATE_MXF_PROBE-yes) $(FATE_MXF_REEL_NAME-yes) $(FATE_MXF_USER_COMMENTS-yes) $(FATE_MXF_FFMPEG_FFPROBE-yes) $(FATE_MXF_OPATOM_USER_COMMENTS-yes) diff --git a/tests/ref/fate/mxf-remux-applehdr10 b/tests/ref/fate/mxf-remux-applehdr10 new file mode 100644 index 0000000000..cc9ea1df6c --- /dev/null +++ b/tests/ref/fate/mxf-remux-applehdr10 @@ -0,0 +1,68 @@ +1b71f29a5c65646cdcc16f1311594113 *tests/data/fate/mxf-remux-applehdr10.mxf +323641 tests/data/fate/mxf-remux-applehdr10.mxf +#tb 0: 1001/60000 +#media_type 0: video +#codec_id 0: prores +#dimensions 0: 1280x720 +#sar 0: 1/1 +#tb 1: 1/48000 +#media_type 1: audio +#codec_id 1: pcm_s24le +#sample_rate 1: 48000 +#channel_layout 1: 4 +#channel_layout_name 1: mono +0, 0, 0, 1, 57008, 0x43416399, S=1, 88 +1, 0, 0, 801, 2403, 0x00000000 +0, 1, 1, 1, 57248, 0xa06cd7b5 +1, 801, 801, 801, 2403, 0x00000000 +0, 2, 2, 1, 57200, 0x5623da10 +1, 1602, 1602, 800, 2400, 0x00000000 +1, 2402, 2402, 801, 2403, 0x00000000 +0, 3, 3, 1, 57152, 0x52d89d3f +1, 3203, 3203, 801, 2403, 0x00000000 +0, 4, 4, 1, 56960, 0x431d5189 +[STREAM] +index=0 +codec_name=prores +codec_tag=0x6f637061 +TAG:file_package_umid=0x060A2B340101010501010D001300000000000000000000000000000000000001 +[SIDE_DATA] +side_data_type=Mastering display metadata +red_x=34000/50000 +red_y=16000/50000 +green_x=13250/50000 +green_y=34500/50000 +blue_x=7500/50000 +blue_y=3000/50000 +white_point_x=15635/50000 +white_point_y=16450/50000 +min_luminance=0/10000 +max_luminance=10000000/10000 +[/SIDE_DATA] +[/STREAM] +[STREAM] +index=1 +codec_name=pcm_s24le +codec_tag=0x0000 +TAG:file_package_umid=0x060A2B340101010501010D001300000000000000000000000000000000000001 +[/STREAM] +[STREAM] +index=2 +codec_name=pcm_s24le +codec_tag=0x0000 +TAG:file_package_umid=0x060A2B340101010501010D001300000000000000000000000000000000000001 +[/STREAM] +[FORMAT] +TAG:operational_pattern_ul=060e2b34.04010101.0d010201.01010900 +TAG:uid=adab4424-2f25-4dc7-92ff-29bd000c0000 +TAG:generation_uid=adab4424-2f25-4dc7-92ff-29bd000c0001 +TAG:company_name=FFmpeg +TAG:product_name=OP1a Muxer +TAG:product_version_num=0.0.0.0.0 +TAG:product_version=0.0.0 +TAG:application_platform=Lavf +TAG:product_uid=adab4424-2f25-4dc7-92ff-29bd000c0002 +TAG:toolkit_version_num=0.0.0.0.0 +TAG:material_package_umid=0x060A2B340101010501010D001300000000000000000000000000000000000000 +TAG:timecode=00:01:15;26 +[/FORMAT] -- 2.30.2
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
Also covers writing mastering display metadata.
So you're merging the D-10 user comments test and ProRes remuxing? What about remuxing D-10? /Tomas
Tomas Härdin:
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
Also covers writing mastering display metadata.
So you're merging the D-10 user comments test and ProRes remuxing? What about remuxing D-10?
No, I am adding a new test; the old test is still there. And both of the mxf-d10-user-comments as well as mxf-remux-applehdr10 have a set of common prerequisites (file and pipe protocols, mxf demuxer, framecrc muxer), so I wanted to factor that out and did it wrong: Instead of "FATE_MXF_FFMPEG_FFPROBE-$(call ALLYES, DVVIDEO_DECODER SCALE_FILTER" it should be "FATE_MXF_REMUX_PROBE-$(call ALLYES, DVVIDEO_DECODER SCALE_FILTER". - Andreas
These tests exhibit two bugs: Instead of using the in-band extradata the demuxer makes up some extradata designed for AVC intra tracks that lack in-band extradata; these files are nevertheless decodable because of the in-band extradata. Furthermore, the frame reordering is lost. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- tests/fate/mxf.mak | 22 ++++++++++- tests/ref/fate/mxf-remux-h264 | 37 ++++++++++++++++++ tests/ref/fate/mxf-remux-xavc | 71 +++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 tests/ref/fate/mxf-remux-h264 create mode 100644 tests/ref/fate/mxf-remux-xavc diff --git a/tests/fate/mxf.mak b/tests/fate/mxf.mak index f96f4a429b..58a697cd86 100644 --- a/tests/fate/mxf.mak +++ b/tests/fate/mxf.mak @@ -42,6 +42,21 @@ FATE_MXF_REMUX_PROBE-$(call ALLYES, PRORES_DECODER MXF_MUXER) \ += fate-mxf-remux-applehdr10 fate-mxf-remux-applehdr10: CMD = transcode mxf $(TARGET_SAMPLES)/mxf/Meridian-Apple_ProResProxy-HDR10.mxf mxf "-map 0 -c copy" "-c copy -t 0.3" "" "-show_entries format_tags:stream_side_data_list:stream=index,codec_name,codec_tag:stream_tags" +# Tests muxing H.264, in particular automatic insertion of h264_mp4toannexb. +# FIXME: The timestamps of the demuxed file are not properly reordered. +# Furthermore the extradata is wrong: It is one of the AVC intra SPS/PPS; +# decoding only works due to in-band extradata. +FATE_MXF_REMUX-$(call ALLYES, MOV_DEMUXER H264_MP4TOANNEXB_BSF \ + MXF_MUXER H264_PARSER H264_DECODER \ + RAWVIDEO_ENCODER) += fate-mxf-remux-h264 +fate-mxf-remux-h264: CMD = transcode mov $(TARGET_SAMPLES)/mov/spherical.mov mxf "-c copy" "-map 0 -map 0 -c:v:1 copy -frames:v 12" + +# Tests remuxing H.264 and data streams. +# The same FIXME as for mxf-remux-h264 applies. +FATE_MXF_REMUX-$(call ALLYES, MXF_MUXER H264_PARSER H264_DECODER) \ + += fate-mxf-remux-xavc +fate-mxf-remux-xavc: CMD = transcode mxf $(TARGET_SAMPLES)/h264/SonyXAVC_LongGOP_green_pixelation_early_Frames.MXF mxf "-map 0 -c copy" "-map 0 -c copy" + FATE_MXF_REEL_NAME-$(call ENCDEC2, MPEG2VIDEO, PCM_S16LE, MXF) += fate-mxf-reel_name fate-mxf-reel_name: $(SAMPLES)/mxf/Sony-00001.mxf fate-mxf-reel_name: CMD = md5 -y -i $(TARGET_SAMPLES)/mxf/Sony-00001.mxf -c copy -timecode 00:00:00:00 -metadata "reel_name=test_reel" -fflags +bitexact -f mxf @@ -64,10 +79,13 @@ FATE_MXF-$(CONFIG_MXF_DEMUXER) += $(FATE_MXF) FATE_MXF_FFMPEG_FFPROBE-$(call ALLYES, FILE_PROTOCOL MXF_DEMUXER \ PIPE_PROTOCOL FRAMECRC_MUXER) \ += $(FATE_MXF_REMUX_PROBE-yes) +FATE_MXF_FFMPEG-$(call ALLYES, FILE_PROTOCOL MXF_DEMUXER \ + PIPE_PROTOCOL FRAMECRC_MUXER) \ + += $(FATE_MXF_REMUX-yes) -FATE_SAMPLES_AVCONV += $(FATE_MXF-yes) $(FATE_MXF_REEL_NAME-yes) +FATE_SAMPLES_AVCONV += $(FATE_MXF-yes) $(FATE_MXF_REEL_NAME-yes) $(FATE_MXF_FFMPEG-yes) FATE_SAMPLES_AVCONV += $(FATE_MXF_USER_COMMENTS-yes) $(FATE_MXF_OPATOM_USER_COMMENTS-yes) FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_MXF_FFMPEG_FFPROBE-yes) FATE_SAMPLES_FFPROBE += $(FATE_MXF_PROBE-yes) -fate-mxf: $(FATE_MXF-yes) $(FATE_MXF_PROBE-yes) $(FATE_MXF_REEL_NAME-yes) $(FATE_MXF_USER_COMMENTS-yes) $(FATE_MXF_FFMPEG_FFPROBE-yes) $(FATE_MXF_OPATOM_USER_COMMENTS-yes) +fate-mxf: $(FATE_MXF-yes) $(FATE_MXF_PROBE-yes) $(FATE_MXF_REEL_NAME-yes) $(FATE_MXF_USER_COMMENTS-yes) $(FATE_MXF_FFMPEG-yes) $(FATE_MXF_FFMPEG_FFPROBE-yes) $(FATE_MXF_OPATOM_USER_COMMENTS-yes) diff --git a/tests/ref/fate/mxf-remux-h264 b/tests/ref/fate/mxf-remux-h264 new file mode 100644 index 0000000000..49ce4324c4 --- /dev/null +++ b/tests/ref/fate/mxf-remux-h264 @@ -0,0 +1,37 @@ +a06741f1a308fa0bd755b206d93639d2 *tests/data/fate/mxf-remux-h264.mxf +201273 tests/data/fate/mxf-remux-h264.mxf +#extradata 1: 81, 0x98411475 +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: rawvideo +#dimensions 0: 1920x1080 +#sar 0: 1/1 +#tb 1: 1/25 +#media_type 1: video +#codec_id 1: h264 +#dimensions 1: 1920x1080 +#sar 1: 1/1 +0, 0, 0, 1, 6220800, 0x6a771857 +1, 0, 0, 1, 69157, 0xd6ff5c4d +1, 1, 1, 1, 1103, 0xb8e00551, F=0x0 +1, 2, 2, 1, 141, 0x49232f95, F=0x0 +0, 3, 3, 1, 6220800, 0x92aa1963 +1, 3, 3, 1, 131, 0xe01928c0, F=0x0 +0, 4, 4, 1, 6220800, 0x906014d8 +1, 4, 4, 1, 69, 0xdf5506bc, F=0x0 +0, 5, 5, 1, 6220800, 0xa67a179e +1, 5, 5, 1, 424, 0x408cb97b, F=0x0 +0, 6, 6, 1, 6220800, 0xcf7e1148 +1, 6, 6, 1, 83, 0x5aa5118a, F=0x0 +0, 7, 7, 1, 6220800, 0xd2b623ab +1, 7, 7, 1, 70, 0x39ec0a38, F=0x0 +0, 8, 8, 1, 6220800, 0x97f51b81 +1, 8, 8, 1, 71, 0x55290a92, F=0x0 +0, 9, 9, 1, 6220800, 0x53e01e46 +1, 9, 9, 1, 149, 0x42683340, F=0x0 +0, 10, 10, 1, 6220800, 0xd4d0de99 +1, 10, 10, 1, 78, 0xad8a0c29, F=0x0 +0, 11, 11, 1, 6220800, 0x6f18e3e4 +1, 11, 11, 1, 72, 0x8c1c0caf, F=0x0 +0, 12, 12, 1, 6220800, 0xcfbbe357 +0, 13, 13, 1, 6220800, 0x70cfe436 diff --git a/tests/ref/fate/mxf-remux-xavc b/tests/ref/fate/mxf-remux-xavc new file mode 100644 index 0000000000..7b221208e5 --- /dev/null +++ b/tests/ref/fate/mxf-remux-xavc @@ -0,0 +1,71 @@ +d0fea4450c0f7c51b0af3631025dfa90 *tests/data/fate/mxf-remux-xavc.mxf +1436217 tests/data/fate/mxf-remux-xavc.mxf +#extradata 0: 97, 0xe2f818c1 +#tb 0: 1/25 +#media_type 0: video +#codec_id 0: h264 +#dimensions 0: 1920x1080 +#sar 0: 1/1 +#tb 1: 1/48000 +#media_type 1: audio +#codec_id 1: pcm_s24le +#sample_rate 1: 48000 +#channel_layout 1: 4 +#channel_layout_name 1: mono +#tb 2: 1/48000 +#media_type 2: audio +#codec_id 2: pcm_s24le +#sample_rate 2: 48000 +#channel_layout 2: 4 +#channel_layout_name 2: mono +#tb 3: 1/48000 +#media_type 3: audio +#codec_id 3: pcm_s24le +#sample_rate 3: 48000 +#channel_layout 3: 4 +#channel_layout_name 3: mono +#tb 4: 1/48000 +#media_type 4: audio +#codec_id 4: pcm_s24le +#sample_rate 4: 48000 +#channel_layout 4: 4 +#channel_layout_name 4: mono +#tb 5: 1/25 +#media_type 5: data +#codec_id 5: none +0, 0, 0, 1, 553248, 0xbda0217f +1, 0, 0, 1920, 5760, 0xd5894ac8 +2, 0, 0, 1920, 5760, 0x86314faa +3, 0, 0, 1920, 5760, 0x00000000 +4, 0, 0, 1920, 5760, 0x00000000 +5, 0, 0, 1, 150, 0xc6f20c7f +0, 1, 1, 1, 119985, 0x6ba5546e, F=0x0 +1, 1920, 1920, 1920, 5760, 0x9f71829c +2, 1920, 1920, 1920, 5760, 0x38049906 +3, 1920, 1920, 1920, 5760, 0x00000000 +4, 1920, 1920, 1920, 5760, 0x00000000 +5, 1, 1, 1, 150, 0xc6f20c7f +0, 2, 2, 1, 98815, 0xe47762ff, F=0x0 +0, 2, 3, 1, 257022, 0xd0647527, F=0x0 +1, 3840, 3840, 1920, 5760, 0xf7245421 +2, 3840, 3840, 1920, 5760, 0x5cd058b0 +3, 3840, 3840, 1920, 5760, 0x00000000 +4, 3840, 3840, 1920, 5760, 0x00000000 +5, 2, 2, 1, 150, 0xc6f20c7f +1, 5760, 5760, 1920, 5760, 0x3cef69d8 +2, 5760, 5760, 1920, 5760, 0x176daa39 +3, 5760, 5760, 1920, 5760, 0x00000000 +4, 5760, 5760, 1920, 5760, 0x00000000 +5, 3, 3, 1, 150, 0xc6f20c7f +0, 4, 4, 1, 123833, 0xff7b324e, F=0x0 +1, 7680, 7680, 1920, 5760, 0x6b647758 +2, 7680, 7680, 1920, 5760, 0xbf6f69de +3, 7680, 7680, 1920, 5760, 0x00000000 +4, 7680, 7680, 1920, 5760, 0x00000000 +5, 4, 4, 1, 150, 0xc6f20c7f +0, 5, 5, 1, 117099, 0x7d6aac45, F=0x0 +1, 9600, 9600, 1920, 5760, 0x0958976a +2, 9600, 9600, 1920, 5760, 0xe3957d5e +3, 9600, 9600, 1920, 5760, 0x00000000 +4, 9600, 9600, 1920, 5760, 0x00000000 +5, 5, 5, 1, 150, 0xc6f20c7f -- 2.30.2
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
These tests exhibit two bugs: Instead of using the in-band extradata the demuxer makes up some extradata designed for AVC intra tracks that lack in-band extradata; these files are nevertheless decodable because of the in-band extradata. Furthermore, the frame reordering is lost.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- tests/fate/mxf.mak | 22 ++++++++++- tests/ref/fate/mxf-remux-h264 | 37 ++++++++++++++++++ tests/ref/fate/mxf-remux-xavc | 71 +++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 tests/ref/fate/mxf-remux-h264 create mode 100644 tests/ref/fate/mxf-remux-xavc
diff --git a/tests/fate/mxf.mak b/tests/fate/mxf.mak index f96f4a429b..58a697cd86 100644 --- a/tests/fate/mxf.mak +++ b/tests/fate/mxf.mak @@ -42,6 +42,21 @@ FATE_MXF_REMUX_PROBE-$(call ALLYES, PRORES_DECODER MXF_MUXER) \ += fate-mxf-remux-applehdr10 fate-mxf-remux-applehdr10: CMD = transcode mxf $(TARGET_SAMPLES)/mxf/Meridian-Apple_ProResProxy-HDR10.mxf mxf "-map 0 -c copy" "-c copy -t 0.3" "" "-show_entries format_tags:stream_side_data_list:stream=index,codec_name,codec_tag:s tream_tags" +# Tests muxing H.264, in particular automatic insertion of h264_mp4toannexb. +# FIXME: The timestamps of the demuxed file are not properly reordered. +# Furthermore the extradata is wrong: It is one of the AVC intra SPS/PPS; +# decoding only works due to in-band extradata.
Is this a problem with the samples or the code? Or both? /Tomas
Tomas Härdin:
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
These tests exhibit two bugs: Instead of using the in-band extradata the demuxer makes up some extradata designed for AVC intra tracks that lack in-band extradata; these files are nevertheless decodable because of the in-band extradata. Furthermore, the frame reordering is lost.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- tests/fate/mxf.mak | 22 ++++++++++- tests/ref/fate/mxf-remux-h264 | 37 ++++++++++++++++++ tests/ref/fate/mxf-remux-xavc | 71 +++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 tests/ref/fate/mxf-remux-h264 create mode 100644 tests/ref/fate/mxf-remux-xavc
diff --git a/tests/fate/mxf.mak b/tests/fate/mxf.mak index f96f4a429b..58a697cd86 100644 --- a/tests/fate/mxf.mak +++ b/tests/fate/mxf.mak @@ -42,6 +42,21 @@ FATE_MXF_REMUX_PROBE-$(call ALLYES, PRORES_DECODER MXF_MUXER) \ += fate-mxf-remux-applehdr10 fate-mxf-remux-applehdr10: CMD = transcode mxf $(TARGET_SAMPLES)/mxf/Meridian-Apple_ProResProxy-HDR10.mxf mxf "-map 0 -c copy" "-c copy -t 0.3" "" "-show_entries format_tags:stream_side_data_list:stream=index,codec_name,codec_tag:s tream_tags" +# Tests muxing H.264, in particular automatic insertion of h264_mp4toannexb. +# FIXME: The timestamps of the demuxed file are not properly reordered. +# Furthermore the extradata is wrong: It is one of the AVC intra SPS/PPS; +# decoding only works due to in-band extradata.
Is this a problem with the samples or the code? Or both?
The extradata issue is due to a bug in the demuxer: It always adds extradata for H.264 instead of letting extract_extradata_bsf extract it from the bitstream. See these lines here: https://github.com/FFmpeg/FFmpeg/blob/447cf537746cd9969674ebbd60411b6093603c... The solution for this is of course to detect whether we are dealing with AVC intra data and only adding the extradata in this case. What is the right way to check for this? Is it the presence of the H.264 ul in mxf_intra_only_picture_essence_coding_uls? (Another way would be to check whether the first packet has extradata, but this is probably more involved (we would basically have to reimplement/reuse a part of avformat_find_stream_info() (the part that deals with extract_extradata) ourselves).) I don't know whether the timestamps are due to a bug in the muxer or the demuxer, but the timestamps the muxer receives are properly reordered. - Andreas
ons 2021-11-10 klockan 14:52 +0100 skrev Andreas Rheinhardt:
Tomas Härdin:
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
These tests exhibit two bugs: Instead of using the in-band extradata the demuxer makes up some extradata designed for AVC intra tracks that lack in-band extradata; these files are nevertheless decodable because of the in-band extradata. Furthermore, the frame reordering is lost.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- tests/fate/mxf.mak | 22 ++++++++++- tests/ref/fate/mxf-remux-h264 | 37 ++++++++++++++++++ tests/ref/fate/mxf-remux-xavc | 71 +++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 tests/ref/fate/mxf-remux-h264 create mode 100644 tests/ref/fate/mxf-remux-xavc
diff --git a/tests/fate/mxf.mak b/tests/fate/mxf.mak index f96f4a429b..58a697cd86 100644 --- a/tests/fate/mxf.mak +++ b/tests/fate/mxf.mak @@ -42,6 +42,21 @@ FATE_MXF_REMUX_PROBE-$(call ALLYES, PRORES_DECODER MXF_MUXER) \ += fate-mxf-remux-applehdr10 fate-mxf-remux-applehdr10: CMD = transcode mxf $(TARGET_SAMPLES)/mxf/Meridian-Apple_ProResProxy-HDR10.mxf mxf "- map 0 -c copy" "-c copy -t 0.3" "" "-show_entries format_tags:stream_side_data_list:stream=index,codec_name,codec_t ag:s tream_tags" +# Tests muxing H.264, in particular automatic insertion of h264_mp4toannexb. +# FIXME: The timestamps of the demuxed file are not properly reordered. +# Furthermore the extradata is wrong: It is one of the AVC intra SPS/PPS; +# decoding only works due to in-band extradata.
Is this a problem with the samples or the code? Or both?
The extradata issue is due to a bug in the demuxer: It always adds extradata for H.264 instead of letting extract_extradata_bsf extract it from the bitstream. See these lines here: https://github.com/FFmpeg/FFmpeg/blob/447cf537746cd9969674ebbd60411b6093603c... The solution for this is of course to detect whether we are dealing with AVC intra data and only adding the extradata in this case. What is the right way to check for this? Is it the presence of the H.264 ul in mxf_intra_only_picture_essence_coding_uls? (Another way would be to check whether the first packet has extradata, but this is probably more involved (we would basically have to reimplement/reuse a part of avformat_find_stream_info() (the part that deals with extract_extradata) ourselves).) I don't know whether the timestamps are due to a bug in the muxer or the demuxer, but the timestamps the muxer receives are properly reordered.
Answers to questions like these are in the official SMPTE mapping documents. We should not invent our own hacks. Typically a UL is used to signal this, yes. For AVC-Intra, PPS and SPS seem to be implicit, hence ff_generate_avci_extradata(). For other AVC/H.264 mappings it might be that there's a metadata KLV that stores the extradata, or extradata are to be parsed from the essence. Again, the mapping document should specify this. Do *not* add hacks that try to autodetect this stuff. That just encourages even more hacks and deviations from the standards. Hacks beget hacks. At some point we might have to go through mxfdec.c and limit already existing hacks to only apply to files written by specific MXF encoders. /Tomas
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index d1c4d43a50..3b6604d0d6 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2203,9 +2203,9 @@ static int mxf_parse_dv_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) static const struct { UID uid; int frame_size; - int profile; + uint8_t profile; uint8_t interlaced; - int intra_only; // 1 or 0 when there are separate UIDs for Long GOP and Intra, -1 when Intra/LGOP detection can be ignored + int8_t intra_only; // 1 or 0 when there are separate UIDs for Long GOP and Intra, -1 when Intra/LGOP detection can be ignored } mxf_h264_codec_uls[] = { {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x11,0x01 }, 0, 66, 0, -1 }, // AVC Baseline {{ 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x01,0x31,0x20,0x01 }, 0, 77, 0, -1 }, // AVC Main -- 2.30.2
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index d1c4d43a50..3b6604d0d6 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2203,9 +2203,9 @@ static int mxf_parse_dv_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) static const struct { UID uid; int frame_size; - int profile; + uint8_t profile; uint8_t interlaced; - int intra_only; // 1 or 0 when there are separate UIDs for Long GOP and Intra, -1 when Intra/LGOP detection can be ignored + int8_t intra_only; // 1 or 0 when there are separate UIDs for
Looks OK, and should work as intended since they're at the end of the struct. /Tomas
None of the muxers here has the AVFMT_NOSTREAMS flag set, so it is checked generically that there are streams. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 3b6604d0d6..fd9e2c4c48 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2507,9 +2507,6 @@ static int mxf_write_header(AVFormatContext *s) uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0}; int64_t timestamp = 0; - if (!s->nb_streams) - return -1; - if (s->oformat == &ff_mxf_opatom_muxer && s->nb_streams !=1) { av_log(s, AV_LOG_ERROR, "there must be exactly one stream for mxf opatom\n"); return -1; -- 2.30.2
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
None of the muxers here has the AVFMT_NOSTREAMS flag set, so it is checked generically that there are streams.
Didn't know about AVFMT_NOSTREAMS
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 3 --- 1 file changed, 3 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 3b6604d0d6..fd9e2c4c48 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2507,9 +2507,6 @@ static int mxf_write_header(AVFormatContext *s) uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0}; int64_t timestamp = 0; - if (!s->nb_streams) - return -1;
Looks OK /Tomas
The MXF muxers only write the header after they have received a packet; the actual write_header function does not write anything. So make an init function out of it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index fd9e2c4c48..a6535eb43f 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2500,7 +2500,7 @@ static int mxf_init_timecode(AVFormatContext *s, AVStream *st, AVRational tbc) return av_timecode_init(&mxf->tc, av_inv_q(tbc), 0, 0, s); } -static int mxf_write_header(AVFormatContext *s) +static int mxf_init(AVFormatContext *s) { MXFContext *mxf = s->priv_data; int i, ret; @@ -3261,7 +3261,7 @@ const AVOutputFormat ff_mxf_muxer = { .priv_data_size = sizeof(MXFContext), .audio_codec = AV_CODEC_ID_PCM_S16LE, .video_codec = AV_CODEC_ID_MPEG2VIDEO, - .write_header = mxf_write_header, + .init = mxf_init, .check_bitstream = mxf_check_bitstream, .write_packet = mxf_write_packet, .write_trailer = mxf_write_footer, @@ -3278,7 +3278,7 @@ const AVOutputFormat ff_mxf_d10_muxer = { .priv_data_size = sizeof(MXFContext), .audio_codec = AV_CODEC_ID_PCM_S16LE, .video_codec = AV_CODEC_ID_MPEG2VIDEO, - .write_header = mxf_write_header, + .init = mxf_init, .write_packet = mxf_write_packet, .write_trailer = mxf_write_footer, .deinit = mxf_deinit, @@ -3295,7 +3295,7 @@ const AVOutputFormat ff_mxf_opatom_muxer = { .priv_data_size = sizeof(MXFContext), .audio_codec = AV_CODEC_ID_PCM_S16LE, .video_codec = AV_CODEC_ID_DNXHD, - .write_header = mxf_write_header, + .init = mxf_init, .check_bitstream = mxf_check_bitstream, .write_packet = mxf_write_packet, .write_trailer = mxf_write_footer, -- 2.30.2
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
The MXF muxers only write the header after they have received a packet; the actual write_header function does not write anything. So make an init function out of it.
New API being put to good use. Patch looks OK We could write *some* output if we really wanted to, like the header partition key and klv fill. Not very useful however. /Tomas
(Unless the packet has a size of zero, the packet will run afoul of the cbr_index check a few lines below.) Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index a6535eb43f..c20ba9bfca 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2151,7 +2151,7 @@ static int mxf_parse_dv_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) // Check for minimal frame size if (pkt->size < 120000) - return -1; + return 0; apt = pkt->data[4] & 0x7; vs_pack = pkt->data + 80*5 + 48; -- 2.30.2
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
(Unless the packet has a size of zero, the packet will run afoul of the cbr_index check a few lines below.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index a6535eb43f..c20ba9bfca 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2151,7 +2151,7 @@ static int mxf_parse_dv_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) // Check for minimal frame size if (pkt->size < 120000) - return -1; + return 0;
Might be nicer to have negative return value mean error, just like everywhere else, and change the code further down accordingly. -1 is a crappy return value for mxf_write_packet() I think. But then the other parsing functions should change at the same time. So let's not hold this patch up with that. Looks OK for now. /Tomas
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index c20ba9bfca..cf63340313 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2509,7 +2509,7 @@ static int mxf_init(AVFormatContext *s) if (s->oformat == &ff_mxf_opatom_muxer && s->nb_streams !=1) { av_log(s, AV_LOG_ERROR, "there must be exactly one stream for mxf opatom\n"); - return -1; + return AVERROR(EINVAL); } if (!av_dict_get(s->metadata, "comment_", NULL, AV_DICT_IGNORE_SUFFIX)) @@ -2525,7 +2525,7 @@ static int mxf_init(AVFormatContext *s) if (((i == 0) ^ (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)) && s->oformat != &ff_mxf_opatom_muxer) { av_log(s, AV_LOG_ERROR, "there must be exactly one video stream and it must be the first one\n"); - return -1; + return AVERROR(EINVAL); } if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { @@ -2590,7 +2590,7 @@ static int mxf_init(AVFormatContext *s) ul_index = 4+ntsc; } else { av_log(s, AV_LOG_ERROR, "error MXF D-10 only support 30/40/50 mbit/s\n"); - return -1; + return AVERROR(EINVAL); } sc->codec_ul = &mxf_d10_codec_uls[ul_index]; @@ -2607,13 +2607,13 @@ static int mxf_init(AVFormatContext *s) char bsf_arg[32]; if (st->codecpar->sample_rate != 48000) { av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n"); - return -1; + return AVERROR_PATCHWELCOME; } avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); if (s->oformat == &ff_mxf_d10_muxer) { if (st->index != 1) { av_log(s, AV_LOG_ERROR, "MXF D-10 only support one audio track\n"); - return -1; + return AVERROR(EINVAL); } if (st->codecpar->codec_id != AV_CODEC_ID_PCM_S16LE && st->codecpar->codec_id != AV_CODEC_ID_PCM_S24LE) { @@ -2657,11 +2657,11 @@ static int mxf_init(AVFormatContext *s) sc->index = INDEX_S436M; } else { av_log(s, AV_LOG_ERROR, "track %d: unsupported data type\n", i); - return -1; + return AVERROR(EINVAL); } if (st->index != s->nb_streams - 1) { av_log(s, AV_LOG_ERROR, "data track must be placed last\n"); - return -1; + return AVERROR(EINVAL); } } @@ -2670,7 +2670,7 @@ static int mxf_init(AVFormatContext *s) if (sc->index == -1) { av_log(s, AV_LOG_ERROR, "track %d: could not find essence container ul, " "codec not currently supported in container\n", i); - return -1; + return AVERROR(EINVAL); } } -- 2.30.2
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
Aha, this one does exactly what I just suggested with return values. D'oh! Looks OK of course /Tomas
Tomas Härdin:
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
Aha, this one does exactly what I just suggested with return values. D'oh!
No. It only does this with the errors from init, not from write_packet. The reason for this is that the other errors often blur the line between AVERROR(EINVAL) and AVERROR_INVALIDDATA, so I decided to do nothing about them. - Andreas
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index cf63340313..aa9857fcff 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -421,6 +421,7 @@ typedef struct MXFContext { int track_instance_count; // used to generate MXFTrack uuids int cbr_index; ///< use a constant bitrate index uint8_t unused_tags[MXF_NUM_TAGS]; ///< local tags that we know will not be used + MXFStreamContext timecode_track_priv; } MXFContext; static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType type, int value) @@ -2712,9 +2713,7 @@ static int mxf_init(AVFormatContext *s) mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track)); if (!mxf->timecode_track) return AVERROR(ENOMEM); - mxf->timecode_track->priv_data = av_mallocz(sizeof(MXFStreamContext)); - if (!mxf->timecode_track->priv_data) - return AVERROR(ENOMEM); + mxf->timecode_track->priv_data = &mxf->timecode_track_priv; mxf->timecode_track->index = -1; return 0; @@ -3087,10 +3086,7 @@ static void mxf_deinit(AVFormatContext *s) av_freep(&mxf->index_entries); av_freep(&mxf->body_partition_offset); - if (mxf->timecode_track) { - av_freep(&mxf->timecode_track->priv_data); - av_freep(&mxf->timecode_track); - } + av_freep(&mxf->timecode_track); } static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, int flush) -- 2.30.2
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index cf63340313..aa9857fcff 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -421,6 +421,7 @@ typedef struct MXFContext { int track_instance_count; // used to generate MXFTrack uuids int cbr_index; ///< use a constant bitrate index uint8_t unused_tags[MXF_NUM_TAGS]; ///< local tags that we know will not be used + MXFStreamContext timecode_track_priv; } MXFContext; static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType type, int value) @@ -2712,9 +2713,7 @@ static int mxf_init(AVFormatContext *s) mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track)); if (!mxf->timecode_track) return AVERROR(ENOMEM); - mxf->timecode_track->priv_data = av_mallocz(sizeof(MXFStreamContext)); - if (!mxf->timecode_track->priv_data) - return AVERROR(ENOMEM); + mxf->timecode_track->priv_data = &mxf->timecode_track_priv; mxf->timecode_track->index = -1; return 0; @@ -3087,10 +3086,7 @@ static void mxf_deinit(AVFormatContext *s) av_freep(&mxf->index_entries); av_freep(&mxf->body_partition_offset); - if (mxf->timecode_track) { - av_freep(&mxf->timecode_track->priv_data); - av_freep(&mxf->timecode_track); - } + av_freep(&mxf->timecode_track); } static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, int flush)
Looks OK. We never have more than one timecode track. /Tomas
Tomas Härdin:
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index cf63340313..aa9857fcff 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -421,6 +421,7 @@ typedef struct MXFContext { int track_instance_count; // used to generate MXFTrack uuids int cbr_index; ///< use a constant bitrate index uint8_t unused_tags[MXF_NUM_TAGS]; ///< local tags that we know will not be used + MXFStreamContext timecode_track_priv; } MXFContext; static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType type, int value) @@ -2712,9 +2713,7 @@ static int mxf_init(AVFormatContext *s) mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track)); if (!mxf->timecode_track) return AVERROR(ENOMEM); - mxf->timecode_track->priv_data = av_mallocz(sizeof(MXFStreamContext)); - if (!mxf->timecode_track->priv_data) - return AVERROR(ENOMEM); + mxf->timecode_track->priv_data = &mxf->timecode_track_priv; mxf->timecode_track->index = -1; return 0; @@ -3087,10 +3086,7 @@ static void mxf_deinit(AVFormatContext *s) av_freep(&mxf->index_entries); av_freep(&mxf->body_partition_offset); - if (mxf->timecode_track) { - av_freep(&mxf->timecode_track->priv_data); - av_freep(&mxf->timecode_track); - } + av_freep(&mxf->timecode_track); } static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, int flush)
Looks OK. We never have more than one timecode track.
We also avoid the allocation of the extra AVStream, but somehow it feels even more of a hack to put it into the context than allocating it, although it actually isn't any more of a hack. - Andreas
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfdec.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index af9d33f796..4191e82474 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -1984,22 +1984,15 @@ static int mxf_uid_to_str(UID uid, char **str) static int mxf_umid_to_str(UID ul, UID uid, char **str) { - int i; char *p; p = *str = av_mallocz(sizeof(UID) * 4 + 2 + 1); if (!p) return AVERROR(ENOMEM); snprintf(p, 2 + 1, "0x"); p += 2; - for (i = 0; i < sizeof(UID); i++) { - snprintf(p, 2 + 1, "%.2X", ul[i]); - p += 2; - - } - for (i = 0; i < sizeof(UID); i++) { - snprintf(p, 2 + 1, "%.2X", uid[i]); - p += 2; - } + ff_data_to_hex(p, ul, sizeof(UID), 0); + p += 2 * sizeof(UID); + ff_data_to_hex(p, uid, sizeof(UID), 0); return 0; } -- 2.30.2
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfdec.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index af9d33f796..4191e82474 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -1984,22 +1984,15 @@ static int mxf_uid_to_str(UID uid, char **str) static int mxf_umid_to_str(UID ul, UID uid, char **str) { - int i; char *p; p = *str = av_mallocz(sizeof(UID) * 4 + 2 + 1); if (!p) return AVERROR(ENOMEM); snprintf(p, 2 + 1, "0x");
Could use strncpy() while you're at it. /Tomas
It is just a flag per supported CID. So there is no reason to use an avpriv function for this purpose. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 47 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index aa9857fcff..326ec6a7d6 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2036,29 +2036,30 @@ static int mxf_parse_prores_frame(AVFormatContext *s, AVStream *st, AVPacket *pk } static const struct { - int cid; + uint16_t cid; + uint8_t interlaced; UID codec_ul; } mxf_dnxhd_codec_uls[] = { - { 1235, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x01,0x00,0x00 } }, // 1080p 10bit HIGH - { 1237, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x03,0x00,0x00 } }, // 1080p 8bit MED - { 1238, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x04,0x00,0x00 } }, // 1080p 8bit HIGH - { 1241, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x07,0x00,0x00 } }, // 1080i 10bit HIGH - { 1242, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x08,0x00,0x00 } }, // 1080i 8bit MED - { 1243, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x09,0x00,0x00 } }, // 1080i 8bit HIGH - { 1244, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x0a,0x00,0x00 } }, // 1080i 8bit TR - { 1250, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x10,0x00,0x00 } }, // 720p 10bit - { 1251, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x11,0x00,0x00 } }, // 720p 8bit HIGH - { 1252, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x12,0x00,0x00 } }, // 720p 8bit MED - { 1253, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x13,0x00,0x00 } }, // 720p 8bit LOW - { 1256, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x16,0x00,0x00 } }, // 1080p 10bit 444 - { 1258, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x18,0x00,0x00 } }, // 720p 8bit TR - { 1259, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x19,0x00,0x00 } }, // 1080p 8bit TR - { 1260, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x1a,0x00,0x00 } }, // 1080i 8bit TR MBAFF - { 1270, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x24,0x00,0x00 } }, // DNXHR 444 - { 1271, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x25,0x00,0x00 } }, // DNXHR HQX - { 1272, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x26,0x00,0x00 } }, // DNXHR HQ - { 1273, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x27,0x00,0x00 } }, // DNXHR SQ - { 1274, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x28,0x00,0x00 } }, // DNXHR LB + { 1235, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x01,0x00,0x00 } }, // 1080p 10bit HIGH + { 1237, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x03,0x00,0x00 } }, // 1080p 8bit MED + { 1238, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x04,0x00,0x00 } }, // 1080p 8bit HIGH + { 1241, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x07,0x00,0x00 } }, // 1080i 10bit HIGH + { 1242, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x08,0x00,0x00 } }, // 1080i 8bit MED + { 1243, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x09,0x00,0x00 } }, // 1080i 8bit HIGH + { 1244, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x0a,0x00,0x00 } }, // 1080i 8bit TR + { 1250, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x10,0x00,0x00 } }, // 720p 10bit + { 1251, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x11,0x00,0x00 } }, // 720p 8bit HIGH + { 1252, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x12,0x00,0x00 } }, // 720p 8bit MED + { 1253, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x13,0x00,0x00 } }, // 720p 8bit LOW + { 1256, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x16,0x00,0x00 } }, // 1080p 10bit 444 + { 1258, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x18,0x00,0x00 } }, // 720p 8bit TR + { 1259, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x19,0x00,0x00 } }, // 1080p 8bit TR + { 1260, 1, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x1a,0x00,0x00 } }, // 1080i 8bit TR MBAFF + { 1270, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x24,0x00,0x00 } }, // DNXHR 444 + { 1271, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x25,0x00,0x00 } }, // DNXHR HQX + { 1272, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x26,0x00,0x00 } }, // DNXHR HQ + { 1273, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x27,0x00,0x00 } }, // DNXHR SQ + { 1274, 0, { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0a,0x04,0x01,0x02,0x02,0x71,0x28,0x00,0x00 } }, // DNXHR LB }; static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt) @@ -2077,6 +2078,7 @@ static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt for (i = 0; i < FF_ARRAY_ELEMS(mxf_dnxhd_codec_uls); i++) { if (cid == mxf_dnxhd_codec_uls[i].cid) { sc->codec_ul = &mxf_dnxhd_codec_uls[i].codec_ul; + sc->interlaced = mxf_dnxhd_codec_uls[i].interlaced; break; } } @@ -2098,9 +2100,6 @@ static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt if (frame_size < 0) return 0; - if ((sc->interlaced = avpriv_dnxhd_get_interlaced(cid)) < 0) - return 0; - if (cid >= 1270) { // RI raster av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den, st->codecpar->width, st->codecpar->height, -- 2.30.2
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
It is just a flag per supported CID. So there is no reason to use an avpriv function for this purpose.
This is data duplication. Honestly these ULs should probably live in dnxhddata.c.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 47 ++++++++++++++++++++++-------------------- -- 1 file changed, 23 insertions(+), 24 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index aa9857fcff..326ec6a7d6 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2036,29 +2036,30 @@ static int mxf_parse_prores_frame(AVFormatContext *s, AVStream *st, AVPacket *pk } static const struct { - int cid; + uint16_t cid; + uint8_t interlaced; UID codec_ul; } mxf_dnxhd_codec_uls[] = {
Not sure if the narrowing of types here does any good. You might need to put cid and interlaced after codec_ul. On the other hand UID is uint8_t[] so perhaps it works out. /Tomas
Tomas Härdin:
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
It is just a flag per supported CID. So there is no reason to use an avpriv function for this purpose.
This is data duplication. Honestly these ULs should probably live in dnxhddata.c.
But aren't these ULs mxf-specific? So the right place for them is here in libavformat. And the amount of data duplicated is trivial; furthermore adding a new DNXHD profile then and now requires modifications in two tables, so I don't see a maintenance burden either.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 47 ++++++++++++++++++++++-------------------- -- 1 file changed, 23 insertions(+), 24 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index aa9857fcff..326ec6a7d6 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2036,29 +2036,30 @@ static int mxf_parse_prores_frame(AVFormatContext *s, AVStream *st, AVPacket *pk } static const struct { - int cid; + uint16_t cid; + uint8_t interlaced; UID codec_ul; } mxf_dnxhd_codec_uls[] = {
Not sure if the narrowing of types here does any good. You might need to put cid and interlaced after codec_ul. On the other hand UID is uint8_t[] so perhaps it works out.
The narrowing is irrelevant, as all cid values in use fit into an uint16_t. Why would I need to put it at the end? Do you worry about padding between interlaced and codec_ul? In this case it doesn't matter: It would just be a matter of whether the padding is in the middle or at the end of the structure. - Andreas
tis 2021-11-09 klockan 22:48 +0100 skrev Andreas Rheinhardt:
Tomas Härdin:
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
It is just a flag per supported CID. So there is no reason to use an avpriv function for this purpose.
This is data duplication. Honestly these ULs should probably live in dnxhddata.c.
But aren't these ULs mxf-specific? So the right place for them is here in libavformat. And the amount of data duplicated is trivial; furthermore adding a new DNXHD profile then and now requires modifications in two tables, so I don't see a maintenance burden either.
Right, this improves lavc/lavf separation. I suppose that's OK. Still not the biggest fan of having this kind of data in more than one place, but on the other hand it's constants..
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 47 ++++++++++++++++++++++---------------- ---- -- 1 file changed, 23 insertions(+), 24 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index aa9857fcff..326ec6a7d6 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2036,29 +2036,30 @@ static int mxf_parse_prores_frame(AVFormatContext *s, AVStream *st, AVPacket *pk } static const struct { - int cid; + uint16_t cid; + uint8_t interlaced; UID codec_ul; } mxf_dnxhd_codec_uls[] = {
Not sure if the narrowing of types here does any good. You might need to put cid and interlaced after codec_ul. On the other hand UID is uint8_t[] so perhaps it works out.
The narrowing is irrelevant, as all cid values in use fit into an uint16_t. Why would I need to put it at the end? Do you worry about padding between interlaced and codec_ul? In this case it doesn't matter: It would just be a matter of whether the padding is in the middle or at the end of the structure.
I don't actually care. I just thought it was curious given patch 04 /Tomas
Tomas Härdin:
tis 2021-11-09 klockan 22:48 +0100 skrev Andreas Rheinhardt:
Tomas Härdin:
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
It is just a flag per supported CID. So there is no reason to use an avpriv function for this purpose.
This is data duplication. Honestly these ULs should probably live in dnxhddata.c.
But aren't these ULs mxf-specific? So the right place for them is here in libavformat. And the amount of data duplicated is trivial; furthermore adding a new DNXHD profile then and now requires modifications in two tables, so I don't see a maintenance burden either.
Right, this improves lavc/lavf separation. I suppose that's OK. Still not the biggest fan of having this kind of data in more than one place, but on the other hand it's constants..
Ok, then I'll apply this.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 47 ++++++++++++++++++++++---------------- ---- -- 1 file changed, 23 insertions(+), 24 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index aa9857fcff..326ec6a7d6 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2036,29 +2036,30 @@ static int mxf_parse_prores_frame(AVFormatContext *s, AVStream *st, AVPacket *pk } static const struct { - int cid; + uint16_t cid; + uint8_t interlaced; UID codec_ul; } mxf_dnxhd_codec_uls[] = {
Not sure if the narrowing of types here does any good. You might need to put cid and interlaced after codec_ul. On the other hand UID is uint8_t[] so perhaps it works out.
The narrowing is irrelevant, as all cid values in use fit into an uint16_t. Why would I need to put it at the end? Do you worry about padding between interlaced and codec_ul? In this case it doesn't matter: It would just be a matter of whether the padding is in the middle or at the end of the structure.
I don't actually care. I just thought it was curious given patch 04
/Tomas
It is unused. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/dnxhddata.c | 8 -------- libavcodec/dnxhddata.h | 1 - 2 files changed, 9 deletions(-) diff --git a/libavcodec/dnxhddata.c b/libavcodec/dnxhddata.c index 3a69a0f501..e3b260f328 100644 --- a/libavcodec/dnxhddata.c +++ b/libavcodec/dnxhddata.c @@ -1105,14 +1105,6 @@ int avpriv_dnxhd_get_hr_frame_size(int cid, int w, int h) return FFMAX(result, 8192); } -int avpriv_dnxhd_get_interlaced(int cid) -{ - const CIDEntry *entry = ff_dnxhd_get_cid_table(cid); - if (!entry) - return -1; - return entry->flags & DNXHD_INTERLACED ? 1 : 0; -} - static int dnxhd_find_hr_cid(AVCodecContext *avctx) { switch (avctx->profile) { diff --git a/libavcodec/dnxhddata.h b/libavcodec/dnxhddata.h index 898079cffc..ecb1cd0b2d 100644 --- a/libavcodec/dnxhddata.h +++ b/libavcodec/dnxhddata.h @@ -90,6 +90,5 @@ static av_always_inline uint64_t ff_dnxhd_parse_header_prefix(const uint8_t *buf int avpriv_dnxhd_get_frame_size(int cid); int avpriv_dnxhd_get_hr_frame_size(int cid, int w, int h); -int avpriv_dnxhd_get_interlaced(int cid); #endif /* AVCODEC_DNXHDDATA_H */ -- 2.30.2
The actual frame_size is no longer used since commit 3d38e45eb85c7a2420cb48a9cd45625c28644b2e; and the check for "< 0" is equivalent to the CID being valid. But this is already ensured by mxf_dnxhd_codec_uls containing this CID. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 326ec6a7d6..83f9a778fe 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2066,7 +2066,7 @@ static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt { MXFContext *mxf = s->priv_data; MXFStreamContext *sc = st->priv_data; - int i, cid, frame_size = 0; + int i, cid; if (mxf->header_written) return 1; @@ -2094,12 +2094,6 @@ static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt if (!sc->component_depth) return 0; - if ((frame_size = avpriv_dnxhd_get_frame_size(cid)) == DNXHD_VARIABLE) { - frame_size = avpriv_dnxhd_get_hr_frame_size(cid, st->codecpar->width, st->codecpar->height); - } - if (frame_size < 0) - return 0; - if (cid >= 1270) { // RI raster av_reduce(&sc->aspect_ratio.num, &sc->aspect_ratio.den, st->codecpar->width, st->codecpar->height, -- 2.30.2
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
The actual frame_size is no longer used since commit 3d38e45eb85c7a2420cb48a9cd45625c28644b2e; and the check for "< 0" is equivalent to the CID being valid. But this is already ensured by mxf_dnxhd_codec_uls containing this CID.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 326ec6a7d6..83f9a778fe 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2066,7 +2066,7 @@ static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt { MXFContext *mxf = s->priv_data; MXFStreamContext *sc = st->priv_data; - int i, cid, frame_size = 0; + int i, cid; if (mxf->header_written) return 1; @@ -2094,12 +2094,6 @@ static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt if (!sc->component_depth) return 0; - if ((frame_size = avpriv_dnxhd_get_frame_size(cid)) == DNXHD_VARIABLE) { - frame_size = avpriv_dnxhd_get_hr_frame_size(cid, st-
codecpar->width, st->codecpar->height); - } - if (frame_size < 0) - return 0;
Looks simple enough. Might want Baptiste to chime in given that he authored 3d38e45. /Tomas
Tomas Härdin:
tis 2021-11-09 klockan 19:01 +0100 skrev Andreas Rheinhardt:
The actual frame_size is no longer used since commit 3d38e45eb85c7a2420cb48a9cd45625c28644b2e; and the check for "< 0" is equivalent to the CID being valid. But this is already ensured by mxf_dnxhd_codec_uls containing this CID.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavformat/mxfenc.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 326ec6a7d6..83f9a778fe 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2066,7 +2066,7 @@ static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt { MXFContext *mxf = s->priv_data; MXFStreamContext *sc = st->priv_data; - int i, cid, frame_size = 0; + int i, cid; if (mxf->header_written) return 1; @@ -2094,12 +2094,6 @@ static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt if (!sc->component_depth) return 0; - if ((frame_size = avpriv_dnxhd_get_frame_size(cid)) == DNXHD_VARIABLE) { - frame_size = avpriv_dnxhd_get_hr_frame_size(cid, st-
codecpar->width, st->codecpar->height); - } - if (frame_size < 0) - return 0;
Looks simple enough. Might want Baptiste to chime in given that he authored 3d38e45.
Will apply this tomorrow just in case Baptiste still wants to chime in. - Andreas
It is no longer used in libavformat. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/dnxhd_parser.c | 4 ++-- libavcodec/dnxhddata.c | 4 ++-- libavcodec/dnxhddata.h | 4 ++-- libavcodec/dnxhdenc.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/dnxhd_parser.c b/libavcodec/dnxhd_parser.c index 4ba619c9bb..631ac83860 100644 --- a/libavcodec/dnxhd_parser.c +++ b/libavcodec/dnxhd_parser.c @@ -73,9 +73,9 @@ static int dnxhd_find_frame_end(DNXHDParserContext *dctx, if (cid <= 0) continue; - remaining = avpriv_dnxhd_get_frame_size(cid); + remaining = ff_dnxhd_get_frame_size(cid); if (remaining <= 0) { - remaining = avpriv_dnxhd_get_hr_frame_size(cid, dctx->w, dctx->h); + remaining = ff_dnxhd_get_hr_frame_size(cid, dctx->w, dctx->h); if (remaining <= 0) continue; } diff --git a/libavcodec/dnxhddata.c b/libavcodec/dnxhddata.c index e3b260f328..cb3d4a4c72 100644 --- a/libavcodec/dnxhddata.c +++ b/libavcodec/dnxhddata.c @@ -1083,7 +1083,7 @@ const CIDEntry *ff_dnxhd_get_cid_table(int cid) return NULL; } -int avpriv_dnxhd_get_frame_size(int cid) +int ff_dnxhd_get_frame_size(int cid) { const CIDEntry *entry = ff_dnxhd_get_cid_table(cid); if (!entry) @@ -1091,7 +1091,7 @@ int avpriv_dnxhd_get_frame_size(int cid) return entry->frame_size; } -int avpriv_dnxhd_get_hr_frame_size(int cid, int w, int h) +int ff_dnxhd_get_hr_frame_size(int cid, int w, int h) { const CIDEntry *entry = ff_dnxhd_get_cid_table(cid); int result; diff --git a/libavcodec/dnxhddata.h b/libavcodec/dnxhddata.h index ecb1cd0b2d..861faca4ca 100644 --- a/libavcodec/dnxhddata.h +++ b/libavcodec/dnxhddata.h @@ -88,7 +88,7 @@ static av_always_inline uint64_t ff_dnxhd_parse_header_prefix(const uint8_t *buf return ff_dnxhd_check_header_prefix(prefix); } -int avpriv_dnxhd_get_frame_size(int cid); -int avpriv_dnxhd_get_hr_frame_size(int cid, int w, int h); +int ff_dnxhd_get_frame_size(int cid); +int ff_dnxhd_get_hr_frame_size(int cid, int w, int h); #endif /* AVCODEC_DNXHDDATA_H */ diff --git a/libavcodec/dnxhdenc.c b/libavcodec/dnxhdenc.c index ebfb85341d..ca67964330 100644 --- a/libavcodec/dnxhdenc.c +++ b/libavcodec/dnxhdenc.c @@ -463,7 +463,7 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx) ctx->m.mb_num = ctx->m.mb_height * ctx->m.mb_width; if (ctx->cid_table->frame_size == DNXHD_VARIABLE) { - ctx->frame_size = avpriv_dnxhd_get_hr_frame_size(ctx->cid, + ctx->frame_size = ff_dnxhd_get_hr_frame_size(ctx->cid, avctx->width, avctx->height); av_assert0(ctx->frame_size >= 0); ctx->coding_unit_size = ctx->frame_size; -- 2.30.2
Besides being unused it should not be used at all: The order of options of bitstream filters is not guaranteed to be stable at all. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- I wonder whether the undocumented and widely unknown shorthand stuff in bsf.c should be removed as well. libavformat/utils.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 509c0ecdce..b42f4d5ca0 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1760,13 +1760,7 @@ int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *a } if (args && bsfc->filter->priv_class) { - const AVOption *opt = av_opt_next(bsfc->priv_data, NULL); - const char * shorthand[2] = {NULL}; - - if (opt) - shorthand[0] = opt->name; - - if ((ret = av_opt_set_from_string(bsfc->priv_data, args, shorthand, "=", ":")) < 0) { + if ((ret = av_set_options_string(bsfc->priv_data, args, "=", ":")) < 0) { av_bsf_free(&bsfc); return ret; } -- 2.30.2
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- fftools/ffmpeg_opt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 7aff43d917..ab4c63a362 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -79,7 +79,7 @@ static const char *const opt_name_inter_matrices[] = {"inter_matrix", static const char *const opt_name_chroma_intra_matrices[] = {"chroma_intra_matrix", NULL}; static const char *const opt_name_top_field_first[] = {"top", NULL}; static const char *const opt_name_presets[] = {"pre", "apre", "vpre", "spre", NULL}; -static const char *const opt_name_copy_initial_nonkeyframes[] = {"copyinkfr", NULL}; +static const char *const opt_name_copy_initial_nonkeyframes[] = {"copyinkf", NULL}; static const char *const opt_name_copy_prior_start[] = {"copypriorss", NULL}; static const char *const opt_name_filters[] = {"filter", "af", "vf", NULL}; static const char *const opt_name_filter_scripts[] = {"filter_script", NULL}; -- 2.30.2
On Tue, Nov 9, 2021 at 8:05 PM Andreas Rheinhardt <andreas.rheinhardt@outlook.com> wrote:
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
LGTM. Jan
The earlier code has ignored it for all stream types except video and subtitles, probably because audio was presumed to only consist of keyframes. Yet this assumption is not true for e.g. TrueHD. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- fftools/ffmpeg_opt.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index ab4c63a362..60ee6b16b5 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1655,6 +1655,9 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket)); if (!ost->muxing_queue) exit_program(1); + if (ost->stream_copy) + MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, + ost->copy_initial_nonkeyframes, oc, st); return ost; } @@ -1940,8 +1943,6 @@ static OutputStream *new_video_stream(OptionsContext *o, AVFormatContext *oc, in ost->avfilter = get_ost_filters(o, oc, ost); if (!ost->avfilter) exit_program(1); - } else { - MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc ,st); } if (ost->stream_copy) @@ -2069,8 +2070,6 @@ static OutputStream *new_subtitle_stream(OptionsContext *o, AVFormatContext *oc, subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE; - MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, ost->copy_initial_nonkeyframes, oc, st); - if (!ost->stream_copy) { char *frame_size = NULL; -- 2.30.2
On Tue, Nov 9, 2021 at 8:05 PM Andreas Rheinhardt <andreas.rheinhardt@outlook.com> wrote:
The earlier code has ignored it for all stream types except video and subtitles, probably because audio was presumed to only consist of keyframes. Yet this assumption is not true for e.g. TrueHD.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- fftools/ffmpeg_opt.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index ab4c63a362..60ee6b16b5 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1655,6 +1655,9 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket)); if (!ost->muxing_queue) exit_program(1); + if (ost->stream_copy) + MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, + ost->copy_initial_nonkeyframes, oc, st);
Could use an extra empty line after the previous if that leads to exit_program since the two are not related/grouped. I think we can follow the way it was done for subtitle streams previously, and just skip the ost->stream_copy check? There is no extra initialization done for this logic, and having the correct value always set in "ost" should not be a bad thing (unless I've missed something with my quick check-around) Otherwise LGTM for me. Jan
Jan Ekström:
On Tue, Nov 9, 2021 at 8:05 PM Andreas Rheinhardt <andreas.rheinhardt@outlook.com> wrote:
The earlier code has ignored it for all stream types except video and subtitles, probably because audio was presumed to only consist of keyframes. Yet this assumption is not true for e.g. TrueHD.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- fftools/ffmpeg_opt.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index ab4c63a362..60ee6b16b5 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1655,6 +1655,9 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ost->muxing_queue = av_fifo_alloc(8 * sizeof(AVPacket)); if (!ost->muxing_queue) exit_program(1); + if (ost->stream_copy) + MATCH_PER_STREAM_OPT(copy_initial_nonkeyframes, i, + ost->copy_initial_nonkeyframes, oc, st);
Could use an extra empty line after the previous if that leads to exit_program since the two are not related/grouped.
I think we can follow the way it was done for subtitle streams previously, and just skip the ost->stream_copy check? There is no extra initialization done for this logic, and having the correct value always set in "ost" should not be a bad thing (unless I've missed something with my quick check-around)
Otherwise LGTM for me.
Applied with these changes. - Andreas
On 11/9/2021 2:34 PM, Andreas Rheinhardt wrote:
The mxf and mxf_opatom muxer expect H.264 in Annex B format.
Amazing that nobody noticed this until now. Guess remuxing from mp4/mkv to mxf is not a common scenario. LGTM, just tested a quick remux and without the bsf it just fails.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- The check here is taken from mpegtsenc.
libavformat/mxfenc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index c36ebef932..d1c4d43a50 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -3174,6 +3174,22 @@ static int mxf_interleave(AVFormatContext *s, AVPacket *pkt, return mxf_interleave_get_packet(s, pkt, flush); }
+static int mxf_check_bitstream(AVFormatContext *s, const AVPacket *pkt) +{ + AVStream *const st = s->streams[pkt->stream_index]; + + switch (st->codecpar->codec_id) { + case AV_CODEC_ID_H264: + if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 && + (AV_RB24(pkt->data) != 0x000001 || + (st->codecpar->extradata_size > 0 && + st->codecpar->extradata[0] == 1))) + return ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL); + break; + } + return 1; +} + #define MXF_COMMON_OPTIONS \ { "signal_standard", "Force/set Signal Standard",\ offsetof(MXFContext, signal_standard), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 7, AV_OPT_FLAG_ENCODING_PARAM, "signal_standard"},\ @@ -3249,6 +3265,7 @@ const AVOutputFormat ff_mxf_muxer = { .audio_codec = AV_CODEC_ID_PCM_S16LE, .video_codec = AV_CODEC_ID_MPEG2VIDEO, .write_header = mxf_write_header, + .check_bitstream = mxf_check_bitstream, .write_packet = mxf_write_packet, .write_trailer = mxf_write_footer, .deinit = mxf_deinit, @@ -3282,6 +3299,7 @@ const AVOutputFormat ff_mxf_opatom_muxer = { .audio_codec = AV_CODEC_ID_PCM_S16LE, .video_codec = AV_CODEC_ID_DNXHD, .write_header = mxf_write_header, + .check_bitstream = mxf_check_bitstream, .write_packet = mxf_write_packet, .write_trailer = mxf_write_footer, .deinit = mxf_deinit,
tis 2021-11-09 klockan 18:34 +0100 skrev Andreas Rheinhardt:
The mxf and mxf_opatom muxer expect H.264 in Annex B format.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- The check here is taken from mpegtsenc.
You didn't think to make both muxers share code instead of copy- pasting? /Tomas
Tomas Härdin:
tis 2021-11-09 klockan 18:34 +0100 skrev Andreas Rheinhardt:
The mxf and mxf_opatom muxer expect H.264 in Annex B format.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- The check here is taken from mpegtsenc.
You didn't think to make both muxers share code instead of copy- pasting?
Well, I can share it. The problem is just that I didn't really know where it belongs: mux.c? utils.c? A new file? - Andreas
tis 2021-11-09 klockan 22:07 +0100 skrev Andreas Rheinhardt:
Tomas Härdin:
tis 2021-11-09 klockan 18:34 +0100 skrev Andreas Rheinhardt:
The mxf and mxf_opatom muxer expect H.264 in Annex B format.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- The check here is taken from mpegtsenc.
You didn't think to make both muxers share code instead of copy- pasting?
Well, I can share it. The problem is just that I didn't really know where it belongs: mux.c? utils.c? A new file?
A new file probably, say libavformat/annexb.c Do we ever need to be able to do this kind of stuff in lavc? In that case it could maybe live there. But that again increases coupling between the two libs.. /Tomas
Tomas Härdin:
tis 2021-11-09 klockan 22:07 +0100 skrev Andreas Rheinhardt:
Tomas Härdin:
tis 2021-11-09 klockan 18:34 +0100 skrev Andreas Rheinhardt:
The mxf and mxf_opatom muxer expect H.264 in Annex B format.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- The check here is taken from mpegtsenc.
You didn't think to make both muxers share code instead of copy- pasting?
Well, I can share it. The problem is just that I didn't really know where it belongs: mux.c? utils.c? A new file?
A new file probably, say libavformat/annexb.c
Do we ever need to be able to do this kind of stuff in lavc? In that case it could maybe live there. But that again increases coupling between the two libs..
lavc does not have AVStreams or AVFormatContexts, so sharing code would be absolutely impossible anyway. But one can share ideas: Using a bsf to prepare data for a decoder is also done for certain decoders; see AVCodec.bsfs. These bitstream filters are applied unconditionally and are therefore supposed to detect themselves whether they should do something or whether the data already has the desired form. I am unsure whether this is a better approach; doing the same in lavf would add a problem that lavc does not have: There would be a copy of every non-refcounted packet when using av_write_frame(). - Andreas
ons 2021-11-10 klockan 14:21 +0100 skrev Andreas Rheinhardt:
Tomas Härdin:
tis 2021-11-09 klockan 22:07 +0100 skrev Andreas Rheinhardt:
Tomas Härdin:
tis 2021-11-09 klockan 18:34 +0100 skrev Andreas Rheinhardt:
The mxf and mxf_opatom muxer expect H.264 in Annex B format.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- The check here is taken from mpegtsenc.
You didn't think to make both muxers share code instead of copy- pasting?
Well, I can share it. The problem is just that I didn't really know where it belongs: mux.c? utils.c? A new file?
A new file probably, say libavformat/annexb.c
Do we ever need to be able to do this kind of stuff in lavc? In that case it could maybe live there. But that again increases coupling between the two libs..
lavc does not have AVStreams or AVFormatContexts, so sharing code would be absolutely impossible anyway. But one can share ideas: Using a bsf to prepare data for a decoder is also done for certain decoders; see AVCodec.bsfs. These bitstream filters are applied unconditionally and are therefore supposed to detect themselves whether they should do something or whether the data already has the desired form. I am unsure whether this is a better approach; doing the same in lavf would add a problem that lavc does not have: There would be a copy of every non-refcounted packet when using av_write_frame().
Just noting here that it might be that we shouldn't even insert a BSF. See my comment on patch 03. /Tomas
participants (4)
-
Andreas Rheinhardt -
James Almer -
Jan Ekström -
Tomas Härdin