[FFmpeg-user] Requesting colormatrix advice

markfilipak.imdb at gmail.com markfilipak.imdb at gmail.com
Mon Nov 6 22:20:31 EET 2023


On 11/6/23 11:16, Phil Rhodes via ffmpeg-user wrote:
>   A number of potentially complex interactions govern what's going on here. FFmpeg has never been particularly smart about how it interprets colour and brightness encoding, and it is not very well documented in that regard, but to be fair, files are not always (or even often) marked correctly with flags indicating what they contain, the flags may be nonstandard, etc. It's tricky.

Hello, Phil, Nice to 'speak' with you again. I agree with you. Color is a wilderness.

Below is what x265 expects, so it's what ffmpeg must give it:

--video-signal-type-preset <string>
     Specify combinations of 'colorprim' 'transfer' 'colormatrix' 'range'
     & 'chromaloc'.

     String format: <system>
     This has higher precedence than individual VUI parameters.
     If any individual VUI option is specified together with this, which
     changes the values set corresponding to the system or color-volume,
     it will be discarded.

     <system>        colorprim transfer     colormatrix range   chromaloc
     =============== ========= ============ =========== ======= =========
     BT601_525       smpte170m smpte170m    smpte170m   limited 0
     BT601_626       bt470bg   smpte170m    bt470bg     limited 0
     BT709_YCC       bt709     bt709        bt709       limited 0
     BT709_RGB       bt709     bt709        gbr         limited
     BT2020_YCC_NCL  bt2020    bt2020-10    bt709       limited 2
     BT2020_RGB      bt2020    smpte2084    bt2020nc    limited
     BT2100_HLG_YCC  bt2020    arib-std-b67 bt2020nc    limited 2
     BT2100_HLG_RGB  bt2020    arib-std-b67 gbr         limited
     FR709_RGB       bt709     bt709        gbr         full
     FR2020_RGB      bt2020    bt2020-10    gbr         full
     FRP3D65_YCC     smpte432  bt709        smpte170m   full    1

     String format: <system>:<color-volume>
     The color-volume options can be used only with the system options
     BT2100_PQ_YCC, BT2100_PQ_ICTCP, and BT2100_PQ_RGB. It is
     incompatible with other options.

     <system>        colorprim transfer     colormatrix range   chromaloc
     =============== ========= ============ =========== ======= =========
     BT2100_PQ_YCC   bt2020    smpte2084    bt2020nc    limited 2
     BT2100_PQ_ICTCP bt2020    smpte2084    ictcp       limited 2
     BT2100_PQ_RGB   bt2020    smpte2084    gbr         limited

     <color-volume>  master-display
     =============== =====================================================================
     P3D65x1000n0005 G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(10000000,5)
     P3D65x4000n005  G(13250,34500)B(7500,3000)R(34000,16000)WP(15635,16450)L(40000000,50)
     BT2100x108n0005 G(8500,39850)B(6550,2300)R(34000,146000)WP(15635,16450)L(10000000,1)

--colorprim <integer|string>
     Specify color primaries to use when converting to RGB. Default
     undefined (not signaled)

      0 bt709       3 bt470m       6 smpte240m    9 smpte428
      1 unknown     4 bt470bg      7 film        10 smpte431
      2 reserved    5 smpte170m    8 bt2020      11 smpte432

--transfer <integer|string>
     Specify transfer characteristics. Default undefined (not signaled)

      0 bt709       5 smpte170m   10 iec61966-2-4   15 smpte2084
      1 unknown     6 smpte240m   11 bt1361e        16 smpte428
      2 reserved    7 linear      12 iec61966-2-1   17 arib-std-b67
      3 bt470m      8 log100      13 bt2020-10
      4 bt470bg     9 log316      14 bt2020-12

--colormatrix <integer|string>
     Specify color matrix setting i.e set the matrix coefficients used in
     deriving the luma and chroma. Default undefined (not signaled)

      0 gbr         4 fcc          8 ycgco       12 chroma-derived-nc
      1 bt709       5 bt470bg      9 bt2020nc    13 chroma-derived-c
      2 unknown     6 smpte170m   10 bt2020c     14 ictcp
      3 reserved    7 smpte240m   11 smpte2085


> If it's a blu-ray it'll generally be in 709, unless it's one of the Sony 4K Blu-Rays which uses xvYCC. It's hard to prove a negative but those are the only situations I'm aware of.  Assume what's on the disc will be studio swing 709 unless it is a 4K blu-ray.

It's 1920x1080. I 'heard' of "studio swing". What is it relative to what x265 expects (above)? Do 
you know?

> If it's a blu-ray of a TV show which was shot on film, it will have been scanned and electronically colour corrected for the blu-ray.

Film scanned. Yes. So that's a 1st-level coloration. But red could not have saturated during 
scanning. Otherwise, I couldn't pull more detail from the 'saturated' regions.

> Oversaturation particularly of reds is one of the issues that will arise from mixing up 601 and 709 and scaling issues are another, but there are so many ways this can be wrong, and places to change settings, that I hesitate to speculate further without further info. You are likely to be facing several confounding issues at once.

I feel a headache coming on. Let's assume ffprobe is correct and colormatrix is undefined on the 
discs. That limits things, eh? That limits things a lot.

> If you intend to watch the resulting file on a computer, you should not need to change the colourspace as sRGB and 709 have identical primaries (they do not have identical brightness mapping but it should not look wildly wrong).

Right now I'm watching it on computer.

Well, I'll tell you. Watching 1: my transcode, and 2: the original (with no colormatrix?), and 3: 
the Criterion "Fanny and Alexander", the skin tones in my transcode look a lot more like "Fanny and 
Alexander" than it looks like the original (with no colormatrix?). The original looks bluish in 
addition to red saturating from bright light emitters.

I'd love to tag the original as 'film' and let the bt709 encoding happen and see what results, but I 
don't know how to do that in ffmpeg. Do you?

FFmpeg doesn't have any 'film' color setting, and ffmpeg colormatrix makes no sense if the source's 
colormatrix is 'unknown'.

I'm kinda happy with what I've done: cutting contrast, reducing red and blue, but that's not very 
satisfying or scientific.

Key may be what you mean by 'studio swing'.

 From ffprobe:
level=41
color_range=unknown
color_space=unknown
color_transfer=unknown
color_primaries=unknown

What do you think of this: Paramount did not limit chroma (i.e., 'range=full'). Is there any way I 
could confirm such a statement?



More information about the ffmpeg-user mailing list