Speeding up generation of Kdenlive proxies with nvenc

Background

I've been using kdenlive video editor in the past year or so, and I like it a lot. But sometimes when I edit lots of videos it gets frustrating when the computer needs to stop and load another clip from storage device during preview. It takes a while even on an SSD drive.

Proxies are just low-res re-encodings of the same video, that lets kdenlive load smaller clips, which takes significantly less time and makes the editor more responsive. The proxy clips need to be encoded in the first place, when the videos are originally loaded into the project.

This is where nvenc comes in. NVENC uses nvidia graphics card to greatly speed up video encoding at the price of running proprietary libraries that aren't compiled into a default package.

This guide assumes you are running Debian with nvidia libraries installed and using ffmpeg from deb-multimedia repository.

I did a talk on the basics of setting up nvidia libraries and ffmpeg codec for debian here -- GPU computing in Debian with Alex Volkov I'm using GeForce GTX1060 6GB on running debian testing (bullseye).

For quick video scaling you need to have CUDA Scale Filter however, it's not shipped by default with ffmpeg not even in deb-multimedia repository because it relies on libnppc10 <https://packages.debian.org/bullseye/libnppc10> which is in non-free, and having a dependency on a non-free repository is against the packaging policy of deb-multimedia. So this has to be compiled manually.

Manually compile FFMPEG to add scale_npp support

Install libnppc10 package that provides scale_npp filter.

# apt install libnppc10

Install all build dependencies of ffmpeg

# apt-get build-dep ffmpeg

Find a folder on your computer where the build take place, the whole thing takes about 2.8GB of space. Download source code with the following command.

$ apt-get source ffmpeg

Once ffmpeg source has been downloaded, add the following configuration parameters in debian/rules under CONFIG_ALL variable

CONFIG_ALL = \
--enable-libnpp \
--enable-cuda \

Compile the package. This is going to take a while.

$ dpkg-buildpackage

Now if you go one directory level up, you should see the following packages created at the end of compilation process.

$ ls | grep .deb$
ffmpeg_4.2.1-dmo3_amd64.deb
ffmpeg-dbgsym_4.2.1-dmo3_amd64.deb
ffmpeg-doc_4.2.1-dmo3_all.deb
libavcodec58_4.2.1-dmo3_amd64.deb
libavcodec58-dbgsym_4.2.1-dmo3_amd64.deb
libavcodec-dev_4.2.1-dmo3_amd64.deb
libavdevice58_4.2.1-dmo3_amd64.deb
libavdevice58-dbgsym_4.2.1-dmo3_amd64.deb
libavdevice-dev_4.2.1-dmo3_amd64.deb
libavfilter7_4.2.1-dmo3_amd64.deb
libavfilter7-dbgsym_4.2.1-dmo3_amd64.deb
libavfilter-dev_4.2.1-dmo3_amd64.deb
libavformat58_4.2.1-dmo3_amd64.deb
libavformat58-dbgsym_4.2.1-dmo3_amd64.deb
libavformat-dev_4.2.1-dmo3_amd64.deb
libavresample4_4.2.1-dmo3_amd64.deb
libavresample4-dbgsym_4.2.1-dmo3_amd64.deb
libavresample-dev_4.2.1-dmo3_amd64.deb
libavutil56_4.2.1-dmo3_amd64.deb
libavutil56-dbgsym_4.2.1-dmo3_amd64.deb
libavutil-dev_4.2.1-dmo3_amd64.deb
libpostproc55_4.2.1-dmo3_amd64.deb
libpostproc55-dbgsym_4.2.1-dmo3_amd64.deb
libpostproc-dev_4.2.1-dmo3_amd64.deb
libswresample3_4.2.1-dmo3_amd64.deb
libswresample3-dbgsym_4.2.1-dmo3_amd64.deb
libswresample-dev_4.2.1-dmo3_amd64.deb
libswscale5_4.2.1-dmo3_amd64.deb
libswscale5-dbgsym_4.2.1-dmo3_amd64.deb
libswscale-dev_4.2.1-dmo3_amd64.deb

Install the packages using the following command

# dpkg -i *.deb

Verify that scale_npp filter is available with the following command

$ ffmpeg -hide_banner -filters | grep scale_npp
... scale_npp         V->V       NVIDIA Performance Primitives video scaling and format conversion

Make kdenlive to use scale_npp proxies

Once scale_npp filter is available, let kdenlive use it. I tested this on Kdenlive 19.08.1.

Go to Settings -> Configure Kdenlive -> Proxy Clips

Click settings next to an encoding profile and then add a new profile.

Add new proxy encoding profile

I use the following proxy, specifically for the video output of my Panasonic GH4 in MOV mode. I find if I try to use other codec than aac, I'd get 'Not supported errors'

Profile Name: x264-nvenc-gh4-aac-h264_cuvid

Parameters: -hwaccel cuvid -c:v h264_cuvid -i -vf scale_npp=720:-2 -vcodec h264_nvenc -g 1 -bf 0 -vb 0 -preset fast -acodec aac

File Exension: mov

dialog of profile parameters with the settings above

Then back in 'Configure Kdenlive' window, go to 'Environment' section and in 'Proxy Clips' set concurrent threads to '1'. My video card supports only two streams and by default two proxy clips are processed at once, if I have more streams than that, nvcodec will raise out of memory error.

setting 1 concurrent proxy clip encoding thread

Testing

When selecting proxy clip in the clip preview. During clip encoding Video Engine Utilization in nvidia-settings should be between 60%-100%

Typical gpu utilization when encoding proxies