Developement of Cuda based Tonemapping filter for ffmpeg

Hey guys!

Wanted to post/begin a thread sharing my progress on building a cuda based ffmpeg filter designed to enable tonemaping of HDR content to an HDR colour space. It’s part of a personal project to build a distributed compute cluster for handling load balancing and serving of multimedia to different clients, all in as efficient a package as possible.

the procedure for testing this is at the bottom, but essentially I’ve modified the ffmpeg vf_overlay_cuda.cu kernel.

it’s very much a bodge and proof of concept, but should work. As of now it’s performing reinhard tonemapping (pixel = pxiel* (pixel/(pixel+1)))

This should be adjustable to suit any global curve algorithm extremely easily (hable, clip etc.)

I havent gotten my nano in (waiting to see if I can get a TX2 edu discount since it should be more powerful per dollar and student budget…)

for those interested in the overall project, the repo is here: GitHub - FCLC/Jetson_ffmpeg_trancode_cluster: Goal: Low power cluster capable of serving 24+ streams of 4KHDR60 source transcodes while consuming no more than 100W at peak and idling at less than 10W

syntax will be:
    
ffmpeg -i INPUT -i INPUT -filter_complex 'hwupload_cuda,overlay_cuda' OUTPUT

    This is a bodge for now, since it's only modifying the output of the cuda kernel itself

    to use it, replace ffmpeg/libavfilter/vf_overlay_cuda.cu with this file: https://github.com/Camofelix/Jetson_ffmpeg_trancode_cluster/blob/master/cuda_filter/vf_overlay_cuda.cu

It compiles fine, but can't test without a nano for actual usage.

will require to self build:

git init 

git fetch https://github.com/FFmpeg/FFmpeg.git

cd ffmpeg && make clean

./configure --enable-nonfree --enable-cuda

    mv ~/path/to/this_version_of/vf_overlay_cuda.cu ~/path/to/ffmpeg/libavfilter/vf_overlay_cuda.cu

    make -j

    //get coffee

    ffmpeg -i INPUT -i INPUT -filter_complex 'hwupload_cuda,overlay_cuda' OUTPUT

    ffplay output

    is output different?

    test file: https://4kmedia.org/lg-new-york-hdr-uhd-4k-demo/
1 Like

Hi,
Thanks for the sharing. This provides another alternative for users who needs video encoding/decoding on Jetson platforms.

Update! The bodge used in Post 1 is no longer required!

please proceed as before but with vf_tonemap_cuda.c and .cu. you’ll need the nvidia headers and to add vf_tonemap_cuda to the relevant files in the filters Makefile as well as the configuration script. fffmpeg/doc/writing_filters.txt contains all the relevant documentation for adding new filters. I’m waiting on the powers that be to upstream the new filter (which will mean all cuda platforms will have access to it)

This is part of a larger project for creating a distributed multimedia compute cluster with idle power draw lower than 10w that peaks at no more than 100w!