Log in

View Full Version : How to apply 3dlut to HLG?


Atak_Snajpera
26th September 2021, 13:43
For regular PQ I use this
LoadPlugin("C:\Users\Dave\Documents\Delphi_Projects\RipBot264\_Compiled\Tools\AviSynth plugins\avsresize\avsresize.dll")
LoadPlugin("C:\Users\Dave\Documents\Delphi_Projects\RipBot264\_Compiled\Tools\AviSynth plugins\AVScube\vscube.dll")
video=z_ConvertFormat(video,pixel_type="RGBP16",colorspace_op="2020ncl:st2084:2020:l=>rgb:linear:2020:f", dither_type="none")
video=Cube(video,"C:\Users\Dave\Documents\Delphi_Projects\RipBot264\_Compiled\Profiles\lut\Arabica 12.cube")
video=z_ConvertFormat(video,pixel_type="YUV420P10",colorspace_op="rgb:linear:2020:f=>2020ncl:st2084:2020:l",dither_type="none")

What would be correct MATRIX COEFFICIENTS,TRANSFER CHARACTERISTICS and COLOR PRIMARIES for HLG?

I tried naively replacing st2084 with std-b67 but I got error message saying that conversion could not be performed.

FranceBB
26th September 2021, 14:44
For regular PQ I use this
LoadPlugin("C:\Users\Dave\Documents\Delphi_Projects\RipBot264\_Compiled\Tools\AviSynth plugins\avsresize\avsresize.dll")
LoadPlugin("C:\Users\Dave\Documents\Delphi_Projects\RipBot264\_Compiled\Tools\AviSynth plugins\AVScube\vscube.dll")
video=z_ConvertFormat(video,pixel_type="RGBP16",colorspace_op="2020ncl:st2084:2020:l=>rgb:linear:2020:f", dither_type="none")
video=Cube(video,"C:\Users\Dave\Documents\Delphi_Projects\RipBot264\_Compiled\Profiles\lut\Arabica 12.cube")
video=z_ConvertFormat(video,pixel_type="YUV420P10",colorspace_op="rgb:linear:2020:f=>2020ncl:st2084:2020:l",dither_type="none")

What would be correct MATRIX COEFFICIENTS,TRANSFER CHARACTERISTICS and COLOR PRIMARIES for HLG?

I tried naively replacing st2084 with std-b67 but I got error message saying that conversion could not be performed.

What you put in z_ConvertFormat doesn't matter as its only job is to convert from YUV to RGB, then it's the LUT that has to perform the right conversion.
Now, a couple of things:

1) Some LUTs are Studio RGB and some LUTs are RGB

The difference is that some of them expect a Narrow Range (i.e Limited TV Range RGB) and some other expect a normal Full Range RGB, so you must know which one is which.

2) When I convert using zconvert, I generally trick it by putting the very same input and output values so that it doesn't do anything dodgy in between. The reason is that I wanna do the conversion and I don't want the filter to do it for me.


This is what I do to go from PQ to HLG using a proprietary LUT which I CANNOT share:

#Narrow range in Narrow range out LUT

#From 4:2:2 16bit planar Narrow Range to RGB Planar 16bit Narrow Range
z_ConvertFormat(pixel_type="RGBP16", colorspace_op="2020:2020:2020:limited=>rgb:2020:2020:limited", dither_type="none")

#From PQ to HLG with 16bit precision
Cube("I:\Scambio\WarnerBros\WarnerBros_PQToHLG_MaxCLL_1000.cube", fullrange=true)

#From RGB 16bit planar Narrow Range to YUV422 16bit planar Narrow Range
z_ConvertFormat(pixel_type="YUV422P16", colorspace_op="rgb:2020:2020:limited=>2020:2020:2020:limited", dither_type="none")

Atak_Snajpera
26th September 2021, 15:09
2) When I convert using zconvert, I generally trick it by putting the very same input and output values so that it doesn't do anything dodgy in between. The reason is that I wanna do the conversion and I don't want the filter to do it for me.
Does this mean that we do not need z_ConvertFormat at all and I could just use this?
video=ConvertToPlanarRGB(video,matrix="Rec2020").ConvertBits(16)
video=Cube(video,"C:\Users\Dave\Documents\Delphi_Projects\RipBot264\_Compiled\Profiles\lut\Arabica 12.cube")
video=ConvertToYUV420(video,matrix="Rec2020").ConvertBits(8)

FranceBB
26th September 2021, 15:25
Does this mean that we do not need z_ConvertFormat at all and I could just use this?
video=ConvertToPlanarRGB(video,matrix="Rec2020").ConvertBits(16)
video=Cube(video,"C:\Users\Dave\Documents\Delphi_Projects\RipBot264\_Compiled\Profiles\lut\Arabica 12.cube")
video=ConvertToYUV420(video,matrix="Rec2020").ConvertBits(8)

If the LUT expects normal RGB (so Full Range RGB) and does the conversion, then sure, absolutely.

That's exactly what I do with the open source LUTs I published: https://forum.doom9.org/showthread.php?t=176091

FFVideoSource("example.mxf")
ConvertBits(16)
ConvertToPlanarRGB()
Cube("C:\Programmi\AviSynth+\LUTs\example.cube")


https://github.com/FranceBB/LinearTransformation

Atak_Snajpera
26th September 2021, 15:40
Does it matter if ConvertBits is after ConvertToPlanarRGB ?

Reel.Deel
26th September 2021, 16:17
Does it matter if ConvertBits is after ConvertToPlanarRGB ?

Yes it matters. If the input clip is 8bit and you use ConvertToPlanarRGB() the resulting clip will be 8 bit also. If you want to process in 16bits its best if you convert to 16bit before the rgb conversion.

Atak_Snajpera
26th September 2021, 16:42
Yes it matters. If the input clip is 8bit and you use ConvertToPlanarRGB() the resulting clip will be 8 bit also. If you want to process in 16bits its best if you convert to 16bit before the rgb conversion.

Roger!

DTL
26th September 2021, 18:07
"z_ConvertFormat(video,pixel_type="RGBP16",colorspace_op="2020ncl:st2084:2020:l=>rgb:linear:2020:f", dither_type="none")"

RGBP16 is not enough for PQ in linear domain and full also not helps (but adds more distortions). Max range of 16bit linear about 65000 and PQ linear range is about milions (only fits to about 30bit integer). Better use RGBPS for linear HDR-PQ and full range (though in Float32 it may be not important).

"std-b67"

I also not sure if z_convertformat outputs realy linear if feeded by HLG and with the only available std-b67 option. Also for some reason the param "nominal_luminance" greatly infuence the result and I do not know why. May be try also fmtc_trasnsfer() for converting HLG to linear.

"ConvertToYUV420(video,matrix="Rec2020").ConvertBits(8)"

8bit is too few for HLG-domain. Or do you try to convert to SDR with LUT ?

"If the LUT expects normal RGB (so Full Range RGB) and does the conversion"

If the LUT is designed to have HLG-transfer at input. Also the full or limited range.

Atak_Snajpera
26th September 2021, 18:30
8bit is too few for HLG-domain. Or do you try to convert to SDR with LUT ?
yes. You are right! It should be ConvertBits(10) not 8. My mistake. Simple copy paste error...

FranceBB
26th September 2021, 20:26
yes. You are right! It should be ConvertBits(10) not 8. My mistake. Simple copy paste error...

Then ConvertBits(bits=10, dither=1) would be my suggestion. I always use Floyd Steinberg unless I'm feeding x264 directly in which case I let the Sierra-2-4A error diffusion built into x264 take care of the bit depth reduction.


8bit is too few for HLG-domain.

Yeah and unfortunately back then Sony employees buried their heads in the sand when they released the Sony A7 III which was capable of recording in HLG, but using Full Range 8bit only -.-

tormento
27th September 2021, 19:02
Then ConvertBits(bits=10, dither=1) would be my suggestion. I always use Floyd Steinberg unless I'm feeding x264 directly in which case I let the Sierra-2-4A error diffusion built into x264 take care of the bit depth reduction.
I am having much better results, quality and bitrate wise, with fmtc_bitdepth(bits=10,dmode=8) for x265 and fmtc_bitdepth(bits=8,dmode=8) for x264.

It's a bit faster too than leaving the dithering job to the encoders, at least on my machine.