Log in

View Full Version : Handbrake and two methods of reencoding UHD-4K content


Perenista
22nd March 2025, 16:07
The two methods gave me a difference in brightness/contrast.

Note: this is a 1080p reencode from UHD-4K content. So our goal is to create what would be best to watch in 1080p, I guess calling it "SDR version" is the proper term. We will also assume there isn't any official Blu-ray, created by professional colorists, which is obviously going to be better than whatever we do automatically with this app.

What I can't figure out is which is correct, in the end. The answers at least from AI, were conflicting. It hinted that file #2, which I created later and has less brightness/contrast, may be better.

Reencodes using H.265. The #2 one with a higher bitrate, uses BT.709 and 10-bit for HEVC.

Take a look:

ORIGINAL UHD-4K file (MKV, lossless):

https://pastebin.com/VTmh1Cir

NOW, the file with less bitrate, and increased brightness:

https://pastebin.com/Eqzhb5cF

The #2 one:

https://pastebin.com/cPusHwcD

Any ideas?

+++++++
One thing I learned is that if we disable colourspace for a 4K - 1080p reencode, the final result is 8-bit and clearly bad/wrong, with video artifacts.

Another change I made was to set a fixed bitrate for HANDBRAKE, and disabled "anamorphic", as explained here:

https://forum.doom9.org/showthread.php?t=186022

GeoffreyA
23rd March 2025, 17:23
From an encoding point of view, the second one will be better because of its higher bitrate. The BT.709 trifecta are also set properly, though in practice, it shouldn't make a difference at 1080p. The x265 encoding would be further improved by using the slow or slower preset.

Regarding the HDR to SDR conversion, if it is possible, give FFmpeg and libplacebo a go and see if the results are better.

Collapse all onto a single line, adjusting the crop values, CRF, and other settings as desired:

ffmpeg -init_hw_device vulkan -i INPUT.mkv -map 0:v:0 -vf libplacebo=upscaler=spline36:downscaler=spline36:w=-1:h=1080:
colorspace=bt709:color_trc=bt709:color_primaries=bt709:range=limited:format=yuv420p10le,
crop=1920:1080:0:0:exact=true,sidedata=delete

-c:v libx265 -preset slow -crf 20 -x265-params no-sao=1:deblock=-1,-1:aq-mode=3 OUTPUT.mp4

PatchWorKs
25th March 2025, 17:43
Suggestion for @Perenista: switch to FastFlix (https://fastflix.org/) if you need more controls over encoding parameters...

excellentswordfight
26th March 2025, 10:12
From an encoding point of view, the second one will be better because of its higher bitrate. The BT.709 trifecta are also set properly, though in practice, it shouldn't make a difference at 1080p. The x265 encoding would be further improved by using the slow or slower preset.

Regarding the HDR to SDR conversion, if it is possible, give FFmpeg and libplacebo a go and see if the results are better.

Collapse all onto a single line, adjusting the crop values, CRF, and other settings as desired:

ffmpeg -init_hw_device vulkan -i INPUT.mkv -map 0:v:0 -vf libplacebo=upscaler=spline36:downscaler=spline36:w=-1:h=1080:
colorspace=bt709:color_trc=bt709:color_primaries=bt709:range=limited:format=yuv420p10le,
crop=1920:1080:0:0:exact=true,sidedata=delete

-c:v libx265 -preset slow -crf 20 -x265-params no-sao=1:deblock=-1,-1:aq-mode=3 OUTPUT.mp4
I have not used libplacebo, but im pretty sure TS would like to tonemap from HDR to SDR. Is that done automatically, cause I cannot see that specified in the commandline?

GeoffreyA
26th March 2025, 13:52
I have not used libplacebo, but im pretty sure TS would like to tonemap from HDR to SDR. Is that done automatically, cause I cannot see that specified in the commandline?

It's done automatically, depending on the source and destination. BT.709 matrix, transfer, and primaries were set for the output, so, if the source is HDR, it will perform conversion, tone mapping, etc. For my part, I use the following, more explicit command, but it's not mandatory because those are already the defaults for peak_detect, tonemapping, gamut_mode, and dithering. (Strictly speaking, tonemapping is set to "auto," using "spline" at present.)

-vf libplacebo=upscaler=spline36:downscaler=spline36:w=-1:h=1080:
peak_detect=true:tonemapping=spline:gamut_mode=perceptual:
colorspace=bt709:color_trc=bt709:color_primaries=bt709:range=limited:dithering=blue:
format=yuv420p,crop=%crop%:exact=true,sidedata=delete