[FFmpeg-devel] [PATCH 01/17] avformat/mxfenc: Auto-insert h264_mp4toannexb BSF if needed

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Nov 9 19:34:19 EET 2021


The mxf and mxf_opatom muxer expect H.264 in Annex B format.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at 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



More information about the ffmpeg-devel mailing list