├── .idea ├── vcs.xml └── workspace.xml ├── README.md ├── compile.sh └── conf.sh /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 17 | 18 | 20 | 21 | 23 | { 24 | "associatedIndex": 5 25 | } 26 | 27 | 28 | 31 | { 32 | "keyToString": { 33 | "RunOnceActivity.OpenProjectViewOnStart": "true", 34 | "RunOnceActivity.ShowReadmeOnStart": "true", 35 | "WebServerToolWindowFactoryState": "false", 36 | "git-widget-placeholder": "master", 37 | "node.js.detected.package.eslint": "true", 38 | "node.js.selected.package.eslint": "(autodetect)", 39 | "nodejs_package_manager_path": "npm", 40 | "vue.rearranger.settings.migration": "true" 41 | } 42 | } 43 | 44 | 45 | 46 | 47 | 1691232731187 48 | 57 | 58 | 59 | 60 | 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This guide is to help you compile the latest ffmpeg with Nvidia CUDA and so much external library like libzimg, libplacebo 2 | in your local computer. 3 | The compiled ffmpeg has mostly common filter and other useful filter, support 4 | - CUDA 5 | - CUVID 6 | - Vulkan 7 | - NVENC 8 | - NVDEC 9 | - zscale 10 | - libplacebo 11 | 12 | # Requirements 13 | - Ubuntu 20.04+ LTS 14 | - Nvidia GPU with CUDA support 15 | 16 | # Steps 17 | 1. Install Nvidia driver and CUDA 18 | ```shell 19 | wget -q https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin 20 | mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600 21 | wget -q https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda-repo-ubuntu2004-11-6-local_11.6.0-510.39.01-1_amd64.deb 22 | dpkg -i cuda-repo-ubuntu2004-11-6-local_11.6.0-510.39.01-1_amd64.deb 23 | rm cuda-repo-ubuntu2004-11-6-local_11.6.0-510.39.01-1_amd64.deb 24 | apt-key add /var/cuda-repo-ubuntu2004-11-6-local/7fa2af80.pub 25 | 26 | wget -q https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb 27 | dpkg -i cuda-keyring_1.0-1_all.deb 28 | rm cuda-keyring_1.0-1_all.deb 29 | 30 | cat >/etc/apt/preferences.d/cuda-11.6-pin-1000.pref </etc/apt/preferences.d/libcudnn8-8.2.4-pin-1000.pref <--enable-nvdec | CUDA | GPU decoder & encoder | 83 | | --enable-vulkan
--enable-libshaderc | vulkan
libshaderc | support Vulkan api | 84 | | --enable-libzimg | libzimg2 | zscale filter | 85 | | --enable-libfdk-aac | libfdk-aac-dev | aac support | 86 | | --enable-libx264 | libx264-dev | h264 encoder & decoder | 87 | | --enable-libx265 | libx265-dev | h265/hevc encoder & decoder | 88 | 89 | # Tips for use libplacebo with CUDA 90 | After discuss with libplacebo author, there has some incompatible with ffmpeg master, CUDA. 91 | So if you want to use libplacebo with CUDA, you need to compile libplacebo with version v6.292.1, 92 | and add disable_multiplane=1 in the ffmpeg command. The example command is 93 | ```shell 94 | ./ffmpeg -y -init_hw_device vulkan=vk,disable_multiplane=1 -filter_hw_device vk -hwaccel nvdec -hwaccel_output_format cuda -i input.mp4 -vf "hwupload=derive_device=vulkan,libplacebo=format=yuv420p:colorspace=bt709:color_primaries=bt709:color_trc=bt709,hwupload=derive_device=cuda" -preset:v fast -tune:v hq -rc:v vbr -cq:v 22 -b:v 0 -c:v h264_nvenc -c:a copy libplacebo.cuda.mp4 95 | ``` 96 | you can find more context in this [issue](https://github.com/haasn/libplacebo/issues/187) 97 | -------------------------------------------------------------------------------- /compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | mkdir build-ffmpeg 3 | cd build-ffmpeg 4 | git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git 5 | cd nv-codec-headers && make install && cd ../ 6 | echo 'installed ffnvcodec' 7 | git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg/ 8 | apt-get install -y build-essential yasm cmake libtool libc6 libc6-dev unzip wget libnuma1 libnuma-dev libdrm-dev libass-dev libopus-dev libmp3lame-dev libva-dev libfdk-aac-dev 9 | echo 'installed basic dependencies' 10 | 11 | apt-get install -y libavcodec-dev libavformat-dev libavutil-dev \ 12 | liblilv-0-0 liblilv-dev lilv-utils \ 13 | libiec61883-dev libraw1394-tools libraw1394-doc libraw1394-dev libraw1394-doc libraw1394-tools \ 14 | libavc1394-0 libavc1394-dev libavc1394-tools \ 15 | libbluray-dev libbluray-doc libbluray-bin \ 16 | libbs2b-dev libbs2b0 libcaca-dev libdc1394-22-dev \ 17 | frei0r-plugins-dev ladspa-sdk-dev libgsm1-dev libmysofa-dev \ 18 | flite1-dev libcodec2-dev libopenjp2-7-dev libopenmpt-dev librsvg2-dev \ 19 | librubberband-dev libshine-dev libsnappy-dev libsoxr-dev libssh-dev \ 20 | libspeex-dev libtwolame-dev libvidstab-dev libvpx-dev libwebp-dev \ 21 | libx264-dev libx265-dev libxvidcore-dev libzmq5-dev libzvbi-dev \ 22 | libopenal-dev libomxil-bellagio-dev libjack-dev libcdio-dev libcdparanoia-dev \ 23 | libcdio-dev libcdio-paranoia-dev libsdl2-dev libtheora-dev libgme-dev 24 | echo 'installed extra dependencies' 25 | 26 | mkdir aom 27 | cd aom 28 | git clone https://aomedia.googlesource.com/aom 29 | cmake ./aom && make && make install 30 | echo 'installed aom' 31 | cd .. 32 | 33 | git clone https://github.com/sekrit-twc/zimg.git --recursive 34 | cd zimg 35 | sh autogen.sh && ./configure && make install 36 | echo 'installed zimg' 37 | cd .. 38 | 39 | wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | apt-key add - 40 | wget -qO /etc/apt/sources.list.d/lunarg-vulkan-1.3.250-focal.list https://packages.lunarg.com/vulkan/1.3.250/lunarg-vulkan-1.3.250-focal.list 41 | apt update 42 | apt install -y vulkan-sdk 43 | echo 'installed vulkan' 44 | 45 | apt-get -y install python3-pip 46 | pip3 install meson ninja 47 | git clone --recursive https://code.videolan.org/videolan/libplacebo -b v6.292.1 48 | cd libplacebo 49 | DIR=./build 50 | meson $DIR -Dvulkan-registry=/usr/share/vulkan/registry/vk.xml 51 | ninja -C$DIR install 52 | echo 'installed libplacebo' 53 | cd ../.. 54 | 55 | export PATH=$PATH:/usr/local/cuda/bin 56 | if [ ! -x conf.sh ]; then 57 | chmod a+x conf.sh 58 | fi 59 | cp conf.sh build-ffmpeg/ffmpeg/ 60 | cd build-ffmpeg/ffmpeg 61 | ./conf.sh 62 | make -j 8 63 | make install 64 | echo 'installed ffmpeg' 65 | ldconfig 66 | ./ffmpeg 67 | -------------------------------------------------------------------------------- /conf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ./configure --enable-nonfree --enable-cuda-nvcc --enable-libnpp --extra-cflags=-I/usr/local/cuda/include \ 3 | --extra-ldflags=-L/usr/local/cuda/lib64 --incdir=/usr/include/x86_64-linux-gnu \ 4 | --libdir=/usr/lib/x86_64-linux-gnu --disable-static --enable-shared --enable-cuvid --enable-decoder=aac \ 5 | --enable-decoder=h264 --enable-decoder=h264_cuvid --enable-demuxer=mov \ 6 | --enable-filter=scale --enable-gnutls --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype \ 7 | --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree \ 8 | --enable-nvdec --enable-nvenc --enable-pic --enable-protocol=file --enable-protocol=https \ 9 | --enable-vaapi --enable-libplacebo --enable-vulkan --enable-libshaderc \ 10 | --enable-ladspa --enable-libaom --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 \ 11 | --enable-libflite --enable-libfontconfig --enable-libfribidi --enable-libzimg \ 12 | --enable-libgme --enable-libgsm --enable-libjack --enable-libmysofa \ 13 | --enable-libopenjpeg --enable-libopenmpt --enable-libpulse --enable-librsvg \ 14 | --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex \ 15 | --enable-libssh --enable-libtwolame --enable-libvidstab \ 16 | --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid \ 17 | --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl \ 18 | --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-frei0r 19 | --------------------------------------------------------------------------------