# Canon XF305 MXF problems in Premiere? Transcode your clips to ProRes with FFMPEG!

Recently encountered a weird problem with 1080i MXFs straight out of a Canon XF305. The files would play in VLC, but Premiere Pro CC 2017 on a brand new MacBook Pro or iMac failed soon after starting to decode the video, with a horrible red frame and MXF frame decode errors in the Log. It's pretty nasty, but I'm sure we can wield FFmpeg to fix this for us.

Interestingly, an older Mac Pro (a silver tower running Yosemite 10.10.5 with an ATi 5770 1GB video card) running Premiere Pro CC 2017 did not have any issues decoding the MXFs, so I wonder if there's some additional / different version Pro Video Codecs installed on it...

I fired up MediaInfo to check the file. (If you don't have it, download the 64-bit GUI without installer from the MediaInfo site).

All looked to be OK:

Input #0, mxf, from 'E:\scratch\test\CLIPS001\XF0007\XF000701.MXF':
uid : 05f46a47-8205-4800-80aa-960001e012e3
generation_uid : 05f46a47-8205-4800-812a-960001e012e3
company_name : CANON
product_name : XF305
product_version : 1.00
product_uid : 060e2b34-0401-010d-0e15-005658460000
modification_date: 2018-05-09T02:10:05.000000Z
material_package_umid: 0x060A2B340101010501010D43130000000A05F46B478205800000850001E012E3
timecode : 09:51:05:02

So why is the file failing to work in Premiere?

This Canon MXF decode problem has been around for years: Google "Premiere MXF red frame". Lots of Canons seem to produce problematic MXFs for Premiere. (1, 2, 3, 4...)

The MXFs produced by this Canon XF305 contain MPEG-2 inter-frame videos, lossily compressed to produce I, B(idirectional predicted) and P(redicted) frames grouped as "GOPs" (Groups of Pictures). The highest quality MPEG-2 files you can produce are intra-frame, where the file is a stream of intra frames, each one being one complete picture, but these yield larger file sizes.

Whatever; we can deal with this - let's transcode to a proxy format, for example Apple ProRes 422 HQ. Easy, Premiere likes that, and there's negligible generational quality loss.

However, what happens if you attempt to do this natively in Premiere or After Effects is that you get the same result as attempting to import the MXFs to use them directly: failed encodes, frame decode errors, truncated files, pain and suffering. Yuck.

So, off to trusty FFMPEG!

The following guide assumes you're using Windows, although it's trivial to modify the instructions for Mac or Linux.

Download the latest stable FFMPEG from the FFMPEG web site and place it in a suitable location. No installation required as long as you grab the 'static' version (with all dependencies included in the main executable).

If your MXFs are gathered in a folder or folder structure, no problem. Make a new batch file (.bat) containing the following (obviously Windows only):

for /R %%f in (*.mxf) do (
D:\path\to\ffmpeg.exe -fflags +genpts -i "%%f" -pix_fmt yuv422p10le -vendor ap10 -top -1 -
flags +ilme+ildct -qscale:v 8 -map 0 -c:v prores_ks -profile:v 3 -c:a copy "%%~df%%~pf%%~nf-
prores422hq.mov" %*
)

So what does this do?

The for loop with the /R switch recursively looks through all files in the directory the script is run from. The caveat is that it assumes the start point is the directory the batch script is run from; this could be improved into an argument (so you could specify a different starting folder).

Once inside the loop, the script parses the full path to the video file, and encodes it to ProRes 422 HQ with the following settings:

• Preserves format flags: PTS timestamps
• Pixel format: YUV422P10LE
• "Vendor": Apple (to fool some Macs into thinking it's encoded by a QuickTime/Apple encoder)
• Top field first interlaced
• Along with the flags options, this helps correctly set the interlaced flag for the container - c.f. the QuickTime 'fiel' atom - which indicates the streams are interlaced, not progressive
• Sets flags "ildct" and "ilme" to indicate source video is interlaced, and forces FFMPEG to handle the video as interlaced while encoding to help preserve picture quality
• Defines a QScale value of 8, which produces roughly 120 MBps files with the ProRes encoder (Qscale of 9 produces about 115 MBps)
• 'Maps' all of the MXF's streams out to the destination file in their original order (FFMPEG can reorder or selectively copy a subset of streams if told to)
• For codec:video, use FFMPEG's "prores_ks" encoder, written by Kostya Shishkov - deemed to be the highest quality one in testing, and the only choice if you want to encode Alpha channels (for various reasonsthere are three prores encoders in FFMPEG, but just use Kostya's.)
• Use ProRes profile 3 - ProRes 422 HQ (there are 6 ProRes profiles, with indexes 0 to 5)
• For all codec:audio streams, leave them untouched - do not reencode
• "%%~df%%~pf%%~nf-prores.mov" = save the output file as a MOV, with the same name as the source but with "-prores" appended to it. This is some funky Windows batch file variable expansion...
• %* = pass any further command-line arguments to the command
• This is useful if you want to specify "-y" (or "-n!") to say 'yes' (or 'no' to overwriting any destination files if they already exist.

I get lovely ProRes 422 HQ files as a result, which are correctly flagged as interlaced (and play correctly deinterlaced with VLC or MPC-HC) and, most importantly, are usable in Premiere. Happy days. Thanks, once again, to FFMPEG.

If there's demand for it, I'll modify the script to work on Linux/OSX and publish here. Likewise, if you have any questions, leave them in the commands or tweet me @christopherw.