{width=“300”}
This is a note to self, and could potentially also be useful to others in need of converting “old-school” MPEG-2 files into more modern MPEG-4 files using FFmpeg.
In the fourMs lab we have a bunch of Canon XF105 video cameras that record .MXF files with MPEG-2 compression. This is not a very useful format for other things we are doing, so I often have to recompress them to something else.
Inspecting one of the files, I just also discovered that they record the audio onto two mono channels:
Stream #0:0: Video: mpeg2video (4:2:2), yuv422p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 50000 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
Stream #0:1: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
Stream #0:2: Audio: pcm_s16le, 48000 Hz, mono, s16, 768 kb/s
So I also want to merge these two mono tracks (which are the left and right inputs of the camera) to a stereo track. FFmpeg comes in handy (as always), and I figured out that this little one-liner will do the trick:
ffmpeg -i input.mxf -vf yadif -vcodec libx264 -q:v 3 -filter_complex "[0:a:0][0:a:1]amerge,channelmap=channel_layout=stereo[st]" -map 0:v -map "[st]" output.mp4
An explanation of some of these settings:
- yadif: this is for deinterlacing the video
- libx264: this is probably unnecessary, but forces to use the better MPEG-4 compressor
- q:v 3: I find this to be a good setting for the video compressor
- filter_complex: this complex string (courtesy of reddit) does the merging of the two mono sources
Will probably try to add it to MGT-terminal at some point, but this blog post will suffice for now.