今天在ffmpeg4.1下成功編譯出支持cuda編碼的版本,記錄一下編譯過程。
編譯增加選項--enable-cuda --enable-cuvid --enable-nvenc
如果遇到提示錯誤
ERROR: cuda requested, but not all dependencies are satisfied: ffnvcodec
說明需要下載nvenc的頭文件。
git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
make
sudo make install
安裝後重新編譯,仍然提示找不到ffnvcodec,這時需要把ffnvcodec.pc的路徑加入環境變量中。
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"
重新編譯,遇到新的報錯:
[nvenc_hevc @ 0x3f928c0] Driver does not support the required nvenc API version. Required: 9.1 Found: 8.1
[nvenc_hevc @ 0x3f928c0] The minimum required Nvidia driver for nvenc is 390.25 or newer
猜測原因可能是nv-codec-headers的版本是9.1,但是Nvidia driver版本只支持8.1。查看nv-codec-headers的所有tag,checkout到8.1版本,重新編譯ffmpeg成功。