GeoffreyA
25th October 2024, 14:31
Good afternoon.
In order to convert some HDR 4K films to SDR 1080p, particularly The Lord of the Rings Theatrical, I put together the following script and have been experimenting with it for a couple of months. It seems to work well; but I wonder if doing the tone mapping while the primaries are still at BT.2020 is the right way to proceed. Apart from that, does the process seem correct?
(As a side note, FFmpeg also works well and the result is slightly more saturated. On Interstellar, though, it falls flat when Gargantua takes the stage, showing discolouration. The issue seems to be with zscale. So, I prefer using VapourSynth and fmtconv, whose results are better and closer to the official Blu-ray versions.)
from vapoursynth import core
clip = core.lsmas.LWLibavSource(filename)
clip = clip.fmtc.bitdepth(bits=32)
clip = clip.fmtc.resample(css="444")
clip = clip.fmtc.matrix(mats="2020", matd="rgb")
clip = clip.fmtc.transfer(transs="2084", transd="linear", match=2)
#clip = clip.tonemap.Reinhard(exposure=1, peak=100)
clip = clip.tonemap.Hable(exposure=1.9)
clip = clip.fmtc.resample(w=1920, h=1080, kernel="spline36")
clip = clip.fmtc.primaries(prims="2020", primd="709")
clip = clip.fmtc.transfer(transs="linear", transd="709")
clip = clip.fmtc.matrix(mats="rgb", matd="709")
clip = clip.fmtc.resample(css="420")
clip = clip.fmtc.bitdepth(bits=8)
clip.set_output()
A sample result: https://we.tl/t-VMGijyoSKN
In order to convert some HDR 4K films to SDR 1080p, particularly The Lord of the Rings Theatrical, I put together the following script and have been experimenting with it for a couple of months. It seems to work well; but I wonder if doing the tone mapping while the primaries are still at BT.2020 is the right way to proceed. Apart from that, does the process seem correct?
(As a side note, FFmpeg also works well and the result is slightly more saturated. On Interstellar, though, it falls flat when Gargantua takes the stage, showing discolouration. The issue seems to be with zscale. So, I prefer using VapourSynth and fmtconv, whose results are better and closer to the official Blu-ray versions.)
from vapoursynth import core
clip = core.lsmas.LWLibavSource(filename)
clip = clip.fmtc.bitdepth(bits=32)
clip = clip.fmtc.resample(css="444")
clip = clip.fmtc.matrix(mats="2020", matd="rgb")
clip = clip.fmtc.transfer(transs="2084", transd="linear", match=2)
#clip = clip.tonemap.Reinhard(exposure=1, peak=100)
clip = clip.tonemap.Hable(exposure=1.9)
clip = clip.fmtc.resample(w=1920, h=1080, kernel="spline36")
clip = clip.fmtc.primaries(prims="2020", primd="709")
clip = clip.fmtc.transfer(transs="linear", transd="709")
clip = clip.fmtc.matrix(mats="rgb", matd="709")
clip = clip.fmtc.resample(css="420")
clip = clip.fmtc.bitdepth(bits=8)
clip.set_output()
A sample result: https://we.tl/t-VMGijyoSKN