How to tonemap HDR to SDR - staxrip/staxrip GitHub Wiki
If your hardware or video renderer cannot handle HDR videos, you need to tonemap the source HDR video in order to prevent color wash-out as follows:
Five tonemapping methods are available in StaxRix.
For all methods, you need to disable Import VUI metadata
in Options
> Video
(for template/project) in order to prevent the source VUI metadata from getting into the encoder settings.
For Methods 3 & 4, you need to refer to this how-to and have DGTonemap
or DGHDRtoSDR
ready. And it helps to enable default MT(multi-thread) mode to 2
(MT_MULTI_INSTANCE
) (AVS only).
SetFilterMTMode("DEFAULT_MT_MODE", 2)
(This is also true for Method 2.)
For Method 5, you need to have either an Nvidia graphics card that can run NVEnc
or an AMD graphics card that supports VCEEnc
.
For any method, it is recommended that you construct the script/encoder settings with no source loaded and save the project as a template for later use.
Method 1: LibPlacebo (AVS and VPY, Preview possible)
Starting with v2.26.0, LibPlacebo is integrated in StaxRip for AviSynth and VapourSynth. Once selected, you get a few options to choose from.
Method 2: HDRTools (AVS only, Preview possible)
Starting in v2.7.0, HDRTools is available as the default HDR to SDR tonemapping filter menu.
You can see whether the source HDR video is PQ or HLG on its mediainfo.
FYI, PQ(Perceptual Quantizer) = st2084 = SMPTE ST 2084, and HLG(Hybrid Log-Gamma) = std-b67 = arib-std-b67
Method 3: DGTonemap (AVS only, Preview possible)
A sample filter composition is as follows:
The crucial part is in the red box.
The script code is as follows:
- Convert to
RGBPS
pixel format inBT.2020
colorspace
z_ConvertFormat(pixel_type="RGBPS", colorspace_op="2020ncl:st2084:2020:l=>rgb:linear:2020:l", dither_type="none")
(If the source video is HLG10, then choose std-b67
(=hlg) instead of st2084
(=pq) for transfer function.)
- Tonemap via
DGHable
(orDGReinhard
)
LoadPlugin("%settings_dir%Plugins\AviSynth\DGToneMap\DGTonemap.dll")
DGHable()
- Convert to
YV12
pixel format inBT.709
colorspace
z_ConvertFormat(pixel_type="YV12", colorspace_op="rgb:linear:2020:l=>709:709:709:l", dither_type="ordered")
(Here you can choose other pixel formats, but in such case you need to consider what pixel formats are allowed for the video encoder of your choice.)
For more info on z_ConvertFormat
filter, see here.
Method 4: DGHDRtoSDR (AVS/VS, Preview possible)
A sample AVS filter composition is as follows:
The crucial part is in the red box.
The script code is as follows:
- Convert bit depth to 16 since the input pixel format must be
YUV420P16
forDGHDRtoSDR
.
ConvertBits(16)
- (Implicitly) tonemap via
DGHDRtoSDR
LoadPlugin("%settings_dir%Plugins\Dual\DGHDRtoSDR\DGHDRtoSDR.dll")
DGHDRtoSDR(mode="pq", white=50)
Select a proper transfer function (pq
or hlg
) and a level of brightness based on the source.
Add fulldepth=true
option if you want the output pixel format to be YUV420P16
instead of YV12
.
For reference, see manolito's test result in tweaking DGHDRtoSDR
for better option settings.
--vpp-colorspace
filter in NVEnc or VCEEnc (Preview not available)
Method 5: Embedded In VPP
> Colorspace
, activate Colorspace
filter as follows:
Choose a proper Transfer From
option depending on whether the source video has pq
or hlg
as its transfer function.
Select a proper tonemapping algorithm (Hable
is chosen in the screenshot). Usually customization is not necessary.
The command line should look like this:
The crucial part is in the red box.
--vpp-colorspace matrix=bt2020nc:bt709,colorprim=bt2020:bt709,transfer=smpte2084:bt709,range=auto:auto,hdr2sdr=hable