Convert MXF files with ffmpeg

From artserver wiki
Revision as of 13:54, 25 August 2022 by Andre (talk | contribs) (Text replacement - "Code_Notes" to "Code Notes")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Material Exchange Format .mxf file is a "container" or "wrapper" format which supports a number of different streams of coded "essence", encoded in any of a variety of video and audio compression formats, together with a metadata wrapper which describes the material contained within the MXF file.

ffmpeg -i file.MXF
[h264 @ 0x55edd1853b20] Truncating likely oversized PPS (9469 > 4096)
    Last message repeated 2 times
[mxf @ 0x55edd184d920] decoding for stream 0 failed
Guessed Channel Layout for Input Stream #0.1 : mono
Guessed Channel Layout for Input Stream #0.2 : mono
Guessed Channel Layout for Input Stream #0.3 : mono
Guessed Channel Layout for Input Stream #0.4 : mono

Input #0, mxf, from 'A001C001_17121456_CANON.MXF':
  Metadata:
    uid             : 3b6bb801-8105-4901-802e-903080000010
    generation_uid  : 3b6bb801-8105-4903-802e-903080000010
    company_name    : CANON
    product_name    : EOS C300 Mark II
    product_version : 1.00
    product_uid     : 060e2b34-0401-010d-0e15-0056454f0200
    modification_date: 2017-12-14 22:38:05
    material_package_umid: 0x060A2B340101010501010D4313000000CA3FE412018105800000853080000010
    timecode        : 09:41:04:20
  Duration: 01:27:34.08, start: 0.000000, bitrate: 389044 kb/s
    Stream #0:0: Video: h264 (High 4:2:2 Intra), yuv422p10le(tv, bt709/bt709/unknown), 4096x2160, SAR 1:1 DAR 256:135, 25 fps, 25 tbr, 25 tbn, 50 tbc
    Metadata:
      file_package_umid: 0x060A2B340101010501010D4313000000CA3FE411018105800000853080000010
    Stream #0:1: Audio: pcm_s24le, 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s
    Metadata:
      file_package_umid: 0x060A2B340101010501010D4313000000CA3FE411018105800000853080000010
    Stream #0:2: Audio: pcm_s24le, 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s
    Metadata:
      file_package_umid: 0x060A2B340101010501010D4313000000CA3FE411018105800000853080000010
    Stream #0:3: Audio: pcm_s24le, 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s
    Metadata:
      file_package_umid: 0x060A2B340101010501010D4313000000CA3FE411018105800000853080000010
    Stream #0:4: Audio: pcm_s24le, 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s
    Metadata:
      file_package_umid: 0x060A2B340101010501010D4313000000CA3FE411018105800000853080000010
At least one output file must be specified

streams map

There is 1 video stream in

  • 1 video stream¨ h264, 4096x2160, bit-rate is not metioned
  • 4 audio streams: pcm_s24le, 48000 Hz, mono, s32 (24 bit), 1152 kb/s

ffmpeg can easily extract them with the argument -map.-map 0:0 is Stream #0:0, -map 0:1 the audio stream #0:1

error

We get Error message:

frame= 2996 fps= 11 q=-1.0 size= 5614730kB time=00:01:59.80 bitrate=383938.5kbits/s [NULL @ 0x55ae917b9ec0] Truncating likely oversized PPS (9469 > 4096)

Which is the same warning as it gave us when we were probing the .MXF file

[h264 @ 0x55edd1853b20] Truncating likely oversized PPS (9469 > 4096)

but this only a warning, not an error.

pixel format

yuv422p10le is the pixel format

  • p10le or p indicates it is planar

ffmpeg encoding can be set to different pixel formats with

-pix_fmt yuv422p10le  

Showing available pixel formats:

ffmpeg -pix_fmts

size

4k

Keeping the size at 4K, to work on anything else but a "film", seems quite of an over kill. It makes the encoding very slow, although the bit rate might be the culpit, as we are still at 36492 kb/s, but also size. And a jerky playback, as logged by ffmpeg.

           *************************************************
           **** Audio/Video desynchronisation detected! ****
           *************************************************

This means either the audio or the video is played too slowly.
Possible reasons, problems, workarounds:
- Your system is simply too slow for this file.
     Transcode it to a lower bitrate file with e.g. mpv encoding support.
- Slow video output.
     Try a different --vo driver (--vo=help for a list). Make sure framedrop
     is not disabled, or experiment with different values for --framedrop.
     Make sure you have proper drivers for your GPU installed. If mpv
     autoselects 'VO: [x11]', it's a sure sign your drivers are messed up.
- Playing from a slow network source. Download the file instead.
- Try to find out whether audio/video/subs are causing this by experimenting
  with --no-video, --no-audio, or --no-sub.
If none of this helps you, file a bug report.

But if the bit rate is reduced, the playback is smooth, but the encoding is still slow:

ffmpeg -i input.MXF -acodec libmp3lame -vcodec libx264 -s 4096x2160 -b:v 5000k -t 2 07-4k.mp4 

1080p

I am noting that if I set the size -s 1920x1080 with -vcodec:copy, the output keeps the same size as the input file. Hence I am trying to use -vcodec libx264. And it does change the size, if re-encoded.


ffmpeg -i A024C451_171211BG_CANON.MXF -map 0:0 -vcodec libx264 -s 1920x1080  

Provided a good smooth output with properties:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '04.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.71.100
  Duration: 00:00:54.72, start: 0.000000, bitrate: 4497 kb/s
    Stream #0:0(und): Video: h264 (High 4:2:2) (avc1 / 0x31637661), yuv422p, 1920x1080 [SAR 16:15 DAR 256:135], 4494 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      timecode        : 01:57:53:07
    Stream #0:1(eng): Data: none (tmcd / 0x64636D74)
    Metadata:
      handler_name    : TimeCodeHandler
      timecode        : 01:57:53:07

Note that, without a direct control ffmpeg also reduced the video bit rate from 389044 kb/s in the .MXF to 4494 kb/s

audio

If no -map stream is specified ffmpeg will select the first of the audio stream and produce a mono version

we can extract the individual audio tracks with the following shell one-liner;

ffmpeg -i input.MXF -map 0:1 -acodec libmp3lame output_a1.mp3

Or changing -acodec copy if we want to have the keep the pcm_s24le encoding, resulting in a signaled 24-bit .wav

conclusion

Here is the final commad. I am using .mov container, because I want the audio to be 24-bit pcm, as in the original.

ffmpeg -i input.MXF -acodec copy -vcodec libx264 -s 1920x1080 -b:v 5000k  09-1080-pcm24.mov


2018 Code Notes

Code Notes +
Date"Date" is a type and predefined property provided by Semantic MediaWiki to represent date values.
2018 +