[Cin] HDR -> sdr tonemap on cpu only
Andrew Randrianasulu
randrianasulu at gmail.com
Tue Apr 22 07:16:33 CEST 2025
пн, 21 апр. 2025 г., 16:13 Andrew Randrianasulu <randrianasulu at gmail.com>:
> Many (if not all) ffmpeg guides insist on using either libplacebo (vulkan
> API on GPU) or zscale (not available in some ffmpeg builds).
>
> Here I found collection of .cube files for doing REC2020 TO rec709.
>
> https://www.reddit.com/r/premiere/comments/12t9mh8/convert_hdr_to_sdr/
>
> https://drive.google.com/file/d/1HQGKE5Fzg_W5vsP8wJcmzRIAtCRKevsV/view
>
> I extracted one .cube file and run this ffmpeg command (at 1.4 fps on
> Termux)
>
> ffmpeg -i storage/downloads/iPhone11_4K-recorder_59.940HDR10.mov -vf
> lut3d=file=REC2020PQto709v1.cube:interp=tetrahedral,scale=1280:-2 ~/1.mp4
>
> and it sort of worked, while I think mpv/libplacebo did better job on my
> desktop. But even just in mpv I had tons of dropped frames, and decoding in
> cingg without any tonemapping was at may be 9 fps max, out of 60.
>
> Ow :(
>
> For some reason just throwing F_tonemap to timeline resulted in extremely
> dark image no matter the settings. I pushed it up by brightness/contrast
> native plugin but I do not think you supposed to do that?
>
Oh, here my answer, may be?
https://forum.doom9.org/showpost.php?p=1934075&postcount=94
======
As you probably are aware, Iphone 12 can shoot in HDR HLG BT2020 Dolby
Vision H.265 10bit planar.
The problem is that because of the tiny sensor, it doesn't have many stops,
which in turns doesn't have many nits, however what Apple seems to be doing
is very peculiar and requires a very dedicated matrix of linear
transformation, hence this LUT.
This is the original picture shot by the Iphone 12:
https://i.imgur.com/ubIAcsl.png
The reason why I had to make yet another matrix is that I wasn't really
pleased with what the tonemapping algorithms were producing: on the left
hand side, Reinhard, in the middle, Hable, on the right hand side the
proper HDR HLG BT2020 interpreting both the color curve and color matrix
correctly: https://i.imgur.com/nBNE3q5.png
they came straight from zscale of FFMpeg but similar results can be achieve
in Avisynth with HDRTools.
After spending lots of time tweaking the parameters, I decided to make the
LUT myself and this is what I've got:
It seems that Apple's interpretation of the HLG curve is not exactly based
on the BBC specs as it has a black point that starts very high, way higher
than it should. HLG is known to be an Hybrid curve which starts like a
Linear BT2020 curve, so like SDR, but then changes and approaches its HDR
nature, which is why it can be viewed both on SDR and HDR monitors. In
Apple's implementation, however, this is NOT the case as the black starts
way higher, as if it was a proper logarithmic curve. This creates problems
as it's supposed to start lower and "confuses" tonemapping algorithms.
====
so, in this case custom LUT is way to go ... ?
> sw tonemapper was added to ffmpeg in 2017
>
> https://github.com/FFmpeg/FFmpeg/blob/master/libavfilter/vf_tonemap.c
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cinelerra-gg.org/pipermail/cin/attachments/20250422/2603b33c/attachment-0001.htm>
More information about the Cin
mailing list