Opened 2 years ago

Last modified 2 years ago

#8772 reopened defect

MXF-muxing fails with Error writing trailer of test.mxf Unknown error occurred

Reported by: steipal Owned by:
Priority: minor Component: avformat
Version: git-master Keywords: mxf
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Creating an MXF-file from the attached video fails. Other muxers seem ok.

How to reproduce:

CMD FAILS:
ffmpeg -i hjelpemiddel.avi -max_muxing_queue_size  500 -r 25 -ar 48000 -y -s 1920x1080 -c:a pcm_s16le test.mxf

OUTPUT:
ffmpeg version git-2020-06-28-4cfcfb3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200621
  configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 55.100 / 56. 55.100
  libavcodec     58. 93.100 / 58. 93.100
  libavformat    58. 47.100 / 58. 47.100
  libavdevice    58. 11.100 / 58. 11.100
  libavfilter     7. 86.100 /  7. 86.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, avi, from 'hjelpemiddel.avi':
  Duration: 00:00:10.81, start: 0.000000, bitrate: 3176 kb/s
    Stream #0:0: Video: vc1 (Advanced) (WVC1 / 0x31435657), yuv420p(progressive), 1920x1080, 3139 kb/s, 120 fps, 120 tbr, 120 tbn, 120 tbc
    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (vc1 (native) -> mpeg2video (native))
  Stream #0:1 -> #0:1 (pcm_s16le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
frame=   79 fps=0.0 q=0.0 size=       0kB time=-577014:32:22.77 bitrate=  -0.0kbits/s dup=52 drop=0 speed=N/A    
frame=  155 fps=154 q=0.0 size=       0kB time=-577014:32:22.77 bitrate=  -0.0kbits/s dup=103 drop=0 speed=N/A    
frame=  243 fps=159 q=0.0 size=       0kB time=-577014:32:22.77 bitrate=  -0.0kbits/s dup=162 drop=0 speed=N/A    
Output #0, mxf, to 'z:\test.mxf':
  Metadata:
    encoder         : Lavf58.47.100
    Stream #0:0: Video: mpeg2video (Main), yuv420p(progressive), 1920x1080, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.93.100 mpeg2video
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
    Stream #0:1: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
    Metadata:
      encoder         : Lavc58.93.100 pcm_s16le
Error writing trailer of test.mxf: Unknown error occurred
frame=  272 fps=160 q=31.0 Lsize=       0kB time=00:00:10.84 bitrate=   0.0kbits/s dup=184 drop=0 speed=6.38x    
video:2370kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
CMD WORKS:
ffmpeg -i hjelpemiddel.avi -max_muxing_queue_size  500 -r 25 -ar 48000 -y -s 1920x1080 -c:a pcm_s16le test.ts

OUTPUT:
ffmpeg version git-2020-06-28-4cfcfb3 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200621
  configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libgsm --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 55.100 / 56. 55.100
  libavcodec     58. 93.100 / 58. 93.100
  libavformat    58. 47.100 / 58. 47.100
  libavdevice    58. 11.100 / 58. 11.100
  libavfilter     7. 86.100 /  7. 86.100
  libswscale      5.  8.100 /  5.  8.100
  libswresample   3.  8.100 /  3.  8.100
  libpostproc    55.  8.100 / 55.  8.100
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, avi, from 'hjelpemiddel.avi':
  Duration: 00:00:10.81, start: 0.000000, bitrate: 3176 kb/s
    Stream #0:0: Video: vc1 (Advanced) (WVC1 / 0x31435657), yuv420p(progressive), 1920x1080, 3139 kb/s, 120 fps, 120 tbr, 120 tbn, 120 tbc
    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 8000 Hz, mono, s16, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (vc1 (native) -> mpeg2video (native))
  Stream #0:1 -> #0:1 (pcm_s16le (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
frame=   46 fps=0.0 q=0.0 size=       0kB time=-577014:32:22.77 bitrate=  -0.0kbits/s speed=N/A    
Output #0, mpegts, to 'z:\test.ts':
  Metadata:
    encoder         : Lavf58.47.100
    Stream #0:0: Video: mpeg2video (Main), yuv420p(progressive), 1920x1080, q=2-31, 200 kb/s, 25 fps, 90k tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.93.100 mpeg2video
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: N/A
    Stream #0:1: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
    Metadata:
      encoder         : Lavc58.93.100 pcm_s16le
[mpegts @ 0000023843e5e040] Stream 1, codec pcm_s16le, is muxed as a private data stream and may not be recognized upon reading.
frame=   90 fps=0.0 q=31.0 Lsize=    1154kB time=00:00:10.68 bitrate= 885.5kbits/s speed=  11x    
video:1085kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 6.366741%

So you see, just changing extension from mxf to ts makes it work. Have also tested other muxers like avi, mkv, mp4 without any issues.

Attachments (1)

hjelpemiddel_cut.avi (2.4 MB ) - added by Carl Eugen Hoyos 2 years ago.

Change History (11)

comment:1 by steipal, 2 years ago

Could not attach file due to limitations. The file is 4192 KB. How to solve?

-steipal

comment:2 by mkver, 2 years ago

Upload it at https://streams.videolan.org/upload/. Don't forget to select FFmpeg and to mention the track ticket number.

comment:3 by steipal, 2 years ago

Thanks, done!

-steipal

comment:4 by Carl Eugen Hoyos, 2 years ago

Priority: normalminor

While I agree that the behaviour has many similarities with a bug, the input file has no audio, so assuming that something useful can come out of a conversion is bold: Use -an.

Unrelated to your report: While the input file definitely is broken, please make sure you know what you are doing when converting to mxf, mxf files typically are broken by definition...

by Carl Eugen Hoyos, 2 years ago

Attachment: hjelpemiddel_cut.avi added

comment:5 by steipal, 2 years ago

Using "-an" is not an option as we need to deliver MXF files with audio for our playout system (Quantel). And because ffmpeg seemingly sees an audio track and is able to create other formats from the source, for example mkv (with audio) without throwing error, I assumed this would be the expected behavior also for the MXF muxer. I have no problem with MXF being "different" like I have for the last 10-11 years dealing with creating MXF files using ffmpeg, but usually the MXF-specific warnings or errors are more meaningful than this one so I was surprised. The error is generic and comes from the main fftools/ffmpeg.c and not libavformat/mxfenc.c where it would make more sense if this was MXF specific.

comment:6 by Tomas Härdin, 2 years ago

What kind of thing do you have that spits out AVI files that claim to have audio when they don't? I would suggest addressing that first of all. There's only so much we can do to accommodate weird workflows.

The A/V sync logic in ffmpeg will buffer all of those video packets waiting for audio that never arrives. For any non-trivial file this would eventually exhaust all available memory.

I looked a bit at mxfenc.c, and mxf_write_packet() never gets called. This coupled with MXF being a very picky format leads to problems. A better error message might be in order however.

comment:7 by steipal, 2 years ago

The AVI file in question is distributed by the police from a surveilence camera. We have no control on what kind of files we receive by external providers that are not broadcasters or video professionals.

I guess the problem is how ffmpeg deals with missing essence in various output formats. I would expect the same error on both commands:

ffmpeg.exe -i hjelpemiddel.avi -max_muxing_queue_size 500 -c:v mpeg2video -r 25 -ar 48000 -y -s 1920x1080 -c:a pcm_s16le test.mkv
ffmpeg.exe -i hjelpemiddel.avi -max_muxing_queue_size 500 -c:v mpeg2video -r 25 -ar 48000 -y -s 1920x1080 -c:a pcm_s16le test.mxf

But if you tell me that this is expected behavior, by design and is not going to be "fixed", then I'm fine with that. I just have to deal with it another way. Because all my conversions are automated/scripted I have to be able to detect a bogus audio/video data stream somehow and replace it with dummy stream before creating the command.

comment:8 by Tomas Härdin, 2 years ago

Resolution: wontfix
Status: newclosed
Type: defectenhancement

With MXF you typically mux the audio and video belonging to each EditUnit into the same EssenceContainer to maintain tape compatibility. It also helps keep the index tables small. mxfenc uses this approach, and rewriting it is too much hassle when -an works just as well. $$$ can change this of course.

One thing you can do on your end is to inspect the files using ffprobe -show_packets and see if there's any audio packets at all in the first few seconds of the file. I presume some cameras do have sound, so grep:ing for "audio" would be a way to handle this in a script.

Marking as wontfix for now.

comment:9 by Carl Eugen Hoyos, 2 years ago

Component: undeterminedavformat
Resolution: wontfix
Status: closedreopened
Type: enhancementdefect

The error message can be improved.

comment:10 by Tomas Härdin, 2 years ago

How about something like this?

diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 5a3a609bf6..7a3c505918 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -2955,9 +2955,13 @@ static int mxf_write_footer(AVFormatContext *s)
     AVIOContext *pb = s->pb;
     int i, err;
 
-    if (!mxf->header_written ||
-        (s->oformat == &ff_mxf_opatom_muxer && !mxf->body_partition_offset)) {
-        /* reason could be invalid options/not supported codec/out of memory */
+    /* reason could be invalid options/not supported codec/out of memory */
+    if (!mxf->header_written) {
+        av_log(s, AV_LOG_ERROR, "No header written yet, can't write footer. Severe A/V desync?\n");
+        return AVERROR_UNKNOWN;
+    }
+    if (s->oformat == &ff_mxf_opatom_muxer && !mxf->body_partition_offset) {
+        av_log(s, AV_LOG_ERROR, "No body partition written yet, can't write footer. Severe A/V desync?\n");
         return AVERROR_UNKNOWN;
     }
Note: See TracTickets for help on using tickets.