5

Does anyone know how I can achieve the following color space (bt.709) via FFmpeg?
Here is what I have now in my files...

enter image description here

As you can see there is Format settings, Matrix as default, how can I set it like this :

  • Format settings (Matrix) : Custom or Standard
  • Component Color primaries : BT.709
  • Transfer characteristics : BT.709
  • Matrix coefficients : BT.709

Thank you

2
  • With re-encoding or without?
    – Gyan
    May 16, 2016 at 17:03
  • I would be glad to know any solution with recording and without it May 17, 2016 at 8:58

2 Answers 2

13

With re-encoding, use

ffmpeg -i test.mxf -c copy -c:v mpeg2video -b:v 5000k \
       -color_primaries 1 -color_trc 1 -colorspace 1 out.mxf

In Mediainfo, at the end of the video stream attributes, you should see the three color-related entries. Note that Format settings (Matrix) is related to MPEG quantization and not color.

1
  • Mulvya, Thank you for your help, Indeed -color_primaries 1 -color_trc 1 -colorspace 1 is working, but I would like also to know how to set Format settings (Matrix) : Custom or Standard if it would be possible, thank you. May 25, 2016 at 10:50
9

After much searching, the secret option that has to be passed to ffmpeg for proper BT.709 encoding is found to be inside the video filter feature. Note that the -vf video filter option actually transforms while the other 709 flags just indicate what flags will be included in the container.

This example starts with a 32x32 png that is set to (0, 0, 255) or max blue.

ffmpeg -y -i Blue32x32.png -c:v libx264 -pix_fmt yuv420p -preset:v slow -profile:v baseline -crf 20 -vf scale=out_color_matrix=bt709 -color_primaries bt709 -color_trc bt709 -colorspace bt709 Blue32x32_709.m4v
ffmpeg -y -i Blue32x32_709.m4v Blue32x32_709.y4m
od -v -t u1 Blue32x32_709.y4m

The output of the last command dumps byte values as ints, you should see (Y Cb Cr) values as Y = 32, Cb = 240, Cr = 118 which means the BT.709 conversion matrix is being used in the .m4v file. When decoded back to RGB the transformed color is (2 0 255).

3
  • 4
    "Note that the -vf video filter option actually transforms while the other 709 flags just indicate what flags will be included in the container" Indeed -color_primaries 1 -color_trc 1 -colorspace 1 only writes the metadata information. While the filter approach will transform your content to BT.709 Dec 17, 2018 at 12:22
  • Just FYI, it appears that this ffmpeg command creates only Gamma 1.0 YCbCr data, more info about 709 gamma issues can be found at this SO question stackoverflow.com/questions/53911662/…
    – MoDJ
    Dec 25, 2018 at 0:09
  • Since primaries for sRGB and BT.709 are the same, and AFAIK gamma correction should do nothing to 0000FF, shouldn't we get straight-up RGB-to-YCbCr conversion in this case? I do get Y = 41, Cb = 240, Cr = 110 when following these instructions, and indeed this matches picturetopeople.org/p2p/image_utilities.p2p/… . Where did the "Y = 32, Cb = 240, Cr = 118" values come from?
    – astgtciv
    Oct 28, 2019 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.