Converting MXF files to MP4 with FFmpeg

We have a bunch of Canon XF105 at RITMO, a camera that records MXF files. This is not a particularly useful file format (unless for further processing). Since many of our recordings are just for documentation purposes, we often see the need to convert to MP4. Here I present two solutions for converting MXF files to MP4, both as individual files and a combined file from a folder. These are shell scripts based on the handy FFmpeg.

Convert individual MXF files to individual MP4 files

The first solution is based on converting a bunch of MXF files to individual MP4 files. This is practical if there are multiple, single shots.

Save the script above as, make it executable, with a command like:

chmod u+x

and run the file:


Convert a folder of MXF files to one MP4 file

The second solution is when we have made one long recording, which is split into individual MXF files of 1.9 GB size (the maximum size of FAT32-formatted drives) in the camera. Then the aim is to merge all of these to one MP4 file. This script will do the trick:

Do the same as above to run the script.

Trim video files using FFmpeg

This is a note to self, and hopefully to others, about how to easily and quickly trim videos without recompressing the file.

I often have long video recordings that I want to split or trim. On a side note, sometimes people call this “cropping”, but in my world, cropping is to cut out parts of the image, that is a spatial transformation. Splitting and trimming are temporal transformations. I have another blog post on cropping video files using FFmpeg.

You can split and trim files in most graphical video editing software, but these will typically also recompress the export file. This reduces the quality of the video, and it also takes a long time. A much better solution is to perform “lossless” trimming. Fortunately, there is a way to do this with the beautiful command-line utility FFmpeg. It is available for most platforms and has a ton of different options. So to remember how it is done, here is a simple one-liner:

ffmpeg -i input.mp4 -ss 01:19:27 -to 02:18:51 -c:v copy -c:a copy output.mp4

This will cut out the section from about 1h19min (after the -ss command) to 2h18min (after the -to command). The copy parts of the command are meant to copy both the original audio and video content without recompressing. This means that the above command only takes a few seconds to run.

You may instead want to specify a fixed duration to extract, in which case you can use:

ffmpeg -i input.mp4 -ss 00:01:10 -t 00:01:05 -c:v copy -c:a copy output.mp4

This will extract 1min5sec (using the -t flag) starting from 1min10sec (the -ss flag) in the file. Happy trimming!