diff mbox series

[FFmpeg-devel,v2,6/6] avformat/mxfenc: Discard audio until valid video has been received

Message ID 20210215165549.667105-6-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,v2,1/6] avformat/mxfenc: Never set codec_ul UID to NULL | expand


Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Feb. 15, 2021, 4:55 p.m. UTC
Normally, video packets are muxed before audio packets for mxf (there is
a dedicated interleave function for this); furthermore the first (video)
packet triggers writing the actual header. Yet when the first video packet
fails the checks performed on it, it will be an audio packet that leads
to writing the header and codec_ul (a value set based upon
properties of the bitstream which necessitates actually inspecting
packets) may be wrong. Therefore this commit discards audio packets until
a valid video packet has been received.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Updated the commit message in light of the fact that #7993 is now fixed
by the earlier commit.

 libavformat/mxfenc.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series


diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 72edaa9e30..1c668998e2 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -2887,6 +2887,13 @@  static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt)
     MXFIndexEntry ie = {0};
     int err;
+    if (!mxf->header_written && pkt->stream_index != 0 &&
+        s->oformat != &ff_mxf_opatom_muxer) {
+        av_log(s, AV_LOG_ERROR, "Received non-video packet before "
+                                "header has been written\n");
+        return AVERROR_INVALIDDATA;
+    }
     if (!mxf->cbr_index && !mxf->edit_unit_byte_count && !(mxf->edit_units_count % EDIT_UNITS_PER_BODY)) {
         if ((err = av_reallocp_array(&mxf->index_entries, mxf->edit_units_count
                                      + EDIT_UNITS_PER_BODY, sizeof(*mxf->index_entries))) < 0) {