(Not) HDR10 to sRGB

I’m going to be watching a bunch of 4K movies in High Dynamic Range (i.e., UHD HDR) later this year, and I’m going to be screenshotting a bit. Now, as you can see from that blog post, I’m using an HDMI splitter that sends the UHD HDR bits to the TV, and sends 2K SDR bits to the screenshotting box.

There’s a right way to do the SDR conversion and a wrong way, and the HDMI splitter does it the wrong way.

As that web page explains, if you just do the moral equivalent of

ffmpeg.exe -i input.mkv -vf select=gte(n\,360) -vframes 1 output.png

then you’re going to get washed-out images. HDR10 is a 10-bit BT.2020 colourspace, and we want to end up in the 8-bit BT.709 colour space.

And as that page tells us, you can do that in a pretty sensible way, or… you can just discard some bits and end up with a washed-out low-contrast image.

Here’s an example of what comes out of the SDR port:

You can do something simple like:

convert -contrast-stretch 0.20x0.10% IMG_53.JPG norm.jpg

and get something that looks acceptable:

But that’s obviously not the “correct” transform.

As Wikipedia explains, the HDR10 format uses a static non-linear transform in the Rec. 2020 colour space. The formula is here: It’s a “perceptual quantizer” (PQ). “PQ is a non-linear electro-optical transfer function (EOTF).” So there.

So! Here’s my question, that I also asked here:

Given that we have discarded some bits, there’s no way to get the ideal SDR version of these images. But: What has been discarded is predictable (I’m guessing the upper? lower? bits?), and all the HDR10 math stuff is static.

A helpful person on the ImageMagick forum suggests using a sigmoidal contrast stretch with lots of “auto” in the parameters, and that does give me pretty good results in all the test images, so it’s “good enough”.

But since all the things that have been done to the signal is static, there should be a way to write a static transform from these non-HDR10 images to SDR.

So, like, first convert back to 10-bit space (with zeroes for the missing bits?)

And then just do the inverse of the PQ EOTF, and then chop bits again into SDR, as this explains, using one of the nice algos there.

Surely this must be a fun math challenge for somebody (who isn’t me!).

Included below are a few more screenshots of movies and TV series that are HDR10 according to the TV.

Leave a Reply