Ffmpeg 4K Hdr to 1080P Sdr Hardware Tonemap Conversion ( Opencl)

Having trawled the internet I have finally successfully compiled FFMPEG with OpenCL enabled and this has allowed me to attempt HDR -> SDR Conversion using my NVIDIA P400 ( Stream Limit Patch Applied).

This has been in no small part due to the various detailed guides / explanations from 林正浩. Unfortunately I don't have a HUGE understanding of the commands, and I am more or less copying various different commands to try and achieve what I want!

My issue is Hardware tone mapping seems no quicker than software tone mapping.

The following achieves approx 0.4x speed:

ffmpeg -hwaccel nvdec -init_hw_device opencl=ocl -filter_hw_device ocl -threads 4 -extra_hw_frames 3 -I INPUT.mkv -vf "format=p010,hwupload,tonemap_opencl=t=bt709:r=tv:p=bt709:m=bt709:tonemap=hable:format=p010,hwdownload,format=p010" OUTPUT

A command I had tried previously using software achieved similar 0.6x - 0.4x:

ffmpeg -I INPUT.mkv -vf zscale=t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0,zscale=t=bt709:m=bt709:r=tv,format=yuv420p -c:a copy -max_muxing_queue_size 9999 /dev/shm/output.mkv

I know they are fairly difference commands but like I said; cutting and pasting from various examples.

My question is What is the most efficient command for HW Accelerated Tonemapping HDR -> SDR, and ideally downscaling to 1080p from 4k? ( I haven't pressed that far into my learning)

I hope people can see I have looked into it and not just asked for help; I have tried and failed to find an answer!

Thank you in advance

1 Answer

I managed to find a good compromise in quality and speed; with satisfactory results which for me were : FHD SDR tonemapped output.

For anyone else; this is the command I've decided to use going forward:

ffmpeg -vsync 0 -hwaccel cuda -init_hw_device opencl=ocl -filter_hw_device ocl -extra_hw_frames 3 -threads 16 -c:v hevc_cuvid -resize 1920x1080 -i INPUT -vf "format=p010,hwupload,tonemap_opencl=tonemap=mobius:param=0.01:desat=0:r=tv:p=bt709:t=bt709:m=bt709:format=nv12,hwdownload,format=nv12" -c:a copy -c:s copy -c:v libx264 -max_muxing_queue_size 9999 OUTPUT

This completed a conversion from a 4K UHD Dsic Rip MKV in 67m27s, compared to a file runtime of 2h01m49s so and average conversion rate of 1.8x.

Just as a note, I decided to use software encoding due to the significant quality increase but minimal time increase for encoding .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest