# How can I generate a color-correct h264/MP4 from a DPX sequence using ffmpeg?

We are converting a sequence of DPX files into an MP4. When the artist uses Adobe Media Encoder CC to generate the video, the colors match the original DPX. When we use ffmpeg, the video has a reddish hint. The command used is:

ffmpeg -y -start_number 0101 -i \\path\to\filename.%04d.dpx -pix_fmt yuv420p sample.mp4


How can we generate a video that matches the color of the original DPX files?

Inspecting the files with ffprobe revealed the following differences (correct file/bad file):

• major_brand: mp42 / isom
• minor_version: 0 / 512
• compatible_brands: mp42mp41 / isomiso2avc1mp41
• encoder: not listed / Lavf57.34.102
• Video: h264 (Main) / h264 (High)
• Video: yuv420p(tv, bt709) / yuv420p
• Video: 1920x1080 / 1920x1080 [SAR 1:1 DAR 16:9]
• handler_name: Alias Data Handler / VideoHandler

Probe references: dpx, correct, incorrect

I followed up on the yuv420p(tv, bt709) portion of the encoding and discovered that this refers to the Rec. 709 colorspace for HDTV. In ffmpeg, colorspace is defined by the colormatrix filter. However, you must convert from some colorspace. According to an ffmpeg mailing list conversation, the default colorspace is assumed to be bt601:

ISTR that if you give ffmpeg RGB it assumes its full range, it also by default converts using 601 matrices. Although it has a number of colourspaces defined which can be accessed in the libs using the API, ffmpeg itself makes no use of them (Although I have a nagging feeling that that may not be completely true anymore either).

So the final ffmpeg command that worked was:

ffmpeg -y -start_number 0101 -i \\path\to\filename.%04d.dpx
-vf colormatrix=bt601:bt709 -pix_fmt yuv420p sample.mp4


The color is now correct, but there is no discernible difference in the output from ffprobe or MediaInfo. (In other words, the colorspace of the ffmpeg-generated file does not appear in the output.)

• Add -colorspace 1 to tag the output.
– Gyan
Jul 19, 2016 at 18:32
• @Mulvya great! is there a "tag everything" option? (I couldn't find one) Jul 20, 2016 at 8:57

Recent patches to ffmpeg fixed this issue https://github.com/FFmpeg/FFmpeg/search?q=dpx&type=commits

It now reads range, primaries, matrix and transfer. Not to mention SMPTE timecode and alternate framerate.

There is still a bug that it writes linear transfer on all files.