[Cin] zscale's tonemapping on input

Andrea paz gamberucci.andrea at gmail.com
Sat May 10 15:45:24 CEST 2025


I wrote a theoretical introduction as a basis; but I still don't
really understand how it works in CinGG. I guess I need to re-study
the chapter “ffmpeg interactions”...
Corrections and guidance are welcome.
-------------- next part --------------
ffmpeg embedded in CinGG has filters to perform good scaling and tonemapping of HDR sources (but not only). You can use the “zscale” and “tonemap” filters.

Introduction

zscale is based on the “zlib” library and acts not only on frame resolution (WxH, “rescaling”), but also performs color space conversion (“pixel format conversion”). Rescaling is generally a lossy process; pixel format conversion is lossy if the input and output color spaces are different. zscale is more efficient than “Scale” (based on libswscale) which is the standard for ffmpeg, but is considered to be of lower quality. See: http://underpop.online.fr/f/ffmpeg/help/zscale.htm.gz
Remember, however, that doing scale process in ffmpeg does not lead to optimal results:
- we recommend doing any image resizing outside of ffmpeg, especially if your sources are OpenEXR (Has no associated color space, that is, it is linear) and you are going to do a colorspace conversion, prior to encoding, this will ensure that the filtering is done in linear space, which will produce less artifacts. However the scaling algorithms can still get called when remapping chroma from 4:4:4 to 4:2:2 (or 4:2:0).
- Only converting from RGB or 4:4:4 to 4:2:2 or 4:2:0 is lossless, with no artifacts (But still with loss of color data, of course), all the other scaling options have artifacts of some form.

tonemap works only in linear and therefore needs zscale for linearization and then zscale again for final output. The workflow could be summarized in three theoretical next steps:

1) zscale to linearize the input.
2) tonemap to map HDR input to SDR.
3) zscale to export the output with the chosen SDR color space.
In the ffmpeg language this (and other) workflows are called “filter graphs” and are applied in a single line.


CinGG: HDR  -->  SDR

Let's take the example of wanting to work on an HDR source but, not having suitable hardware to support it, we have to reduce its values to SDR values by tonemapping. In this case the conversion is from a higher subsampling to a lower one and so, if we work well, we should have no loss of quality. It will have to be used zscale because it supports PQ/HLG (HDR) type transfer functions.


More information about the Cin mailing list