I have approximately 1400 .mp4 video files, and I must reencode everything to use mp4box to transform it in DASH

CPU: Intel® Core™ i7-6700 Quad-Core Skylake
GPU: GeForce® GTX 1080
Ram: 64GB
Ubuntu 18.04

After running: apt-get install ffmpeg, I'm not able to use -c:v h264_nvenc, I got an error like: Unknown encoder 'h264_nvenc'

I read every guide on web to install correctly nvidia codecs on my server, but old guides and is not working for my server.

Can you help me find a new and correct way about how to install it?

Thank you.


3 Answers 3


In your case, you'll need to build FFmpeg from source. Use the example shown below. For the supported and available hardware accelerated features you can achieve with a current generation NVENC-capable NVIDIA GPU, see this answer.

For the build:

FFmpeg build with NVENC and all available CUDA-based filters on Ubuntu 18.04LTS:

Build platform: Ubuntu 18.04LTS

Goals: Generate an FFmpeg build that can utilize NVENC and all available CUDA-based filters on Ubuntu 18.04LTS+. The build will be prefixed to /opt.

Ensure the platform is up to date:

sudo apt update && sudo apt -y upgrade && sudo apt -y dist-upgrade

Install baseline dependencies first (inclusive of OpenCL headers+)

sudo apt-get -y install autoconf automake build-essential libass-dev \
libtool libssl-dev \
pkg-config texinfo zlib1g-dev cmake mercurial libbz2-dev rtmpdump librtmp-dev libunistring2 libunistring-dev opencl-headers ocl-icd-*

Create the workspace:

sudo mkdir -p /opt/ffmpeg
mkdir -p ~/ffmpeg_sources

Install CUDA 10 SDK :

Ensure that you have the latest driver:

sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update && sudo apt-get -y upgrade

On Ubuntu 18.04LTS desktop, this should be enough for the current device driver:

sudo apt-get install nvidia-kernel-source-430 nvidia-driver-430

On Ubuntu 18.04LTS server systems, this will do:

sudo apt install nvidia-headless-430 nvidia-utils-430 libnvidia-common-430 libnvidia-encode-430 libnvidia-decode-430 libnvidia-fbc1-430

We keep the device driver up to the latest version so as to pass ffnvcodec driver version check. It's wise to confirm the latest driver version first. Do so by checking the repository here: https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa

Fetch the SDK binary installer first:

cd ~/ffmpeg_sources
wget -c -v -nc https://developer.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.168_418.67_linux.run
chmod +x ./cuda_10.1.168_418.67_linux.run

You'll observe that we're using the binary installer. This is most useful for these who're on headless systems (without X) as it will install CUDA without pulling in unnecessary dependencies.

You could also use the official CUDA repository provided by NVIDIA for Ubuntu, but I cannot recommend it as it pulls in a lot of unnecessary packages.

Confirm that the library configuration file for CUDA libraries also exists with the correct settings:


The content should be:


When done, load the new configuration:

sudo ldconfig -vvvv

Now, set up the environment variables for CUDA:

Edit the /etc/environment file and append the following:


Now, append the PATH variable with the following:


When done, remember to source the file:

source /etc/environment

And proceed.

On NVENC enablement:

Take note that changes to the inclusion of third party headers affects new builds, and this is fixed by:

cd ~/ffmpeg_sources
git clone https://github.com/FFmpeg/nv-codec-headers
cd nv-codec-headers
sudo make install PREFIX="/opt/ffmpeg_build"

Build a usable FFmpeg binary prefixed to /opt/ffmpeg:

Include extra components as needed:

(a). Build and deploy nasm: Nasm is an assembler for x86 optimizations used by x264 and FFmpeg. Highly recommended or your resulting build may be very slow.

Note that we've now switched away from Yasm to nasm, as this is the current assembler that x265,x264, among others, are adopting.

cd ~/ffmpeg_sources
wget https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/nasm-2.14.02.tar.gz
tar xzvf nasm-2.14.02.tar.gz
cd nasm-2.14.02
./configure --prefix="/opt/ffmpeg_build" --bindir="/opt/ffmpeg/bin" 
make -j$(nproc) VERBOSE=1
sudo make -j$(nproc) install
make -j$(nproc) distclean

(b). Build and deploy libx264 statically: This library provides a H.264 video encoder. See the H.264 Encoding Guide for more information and usage examples. This requires ffmpeg to be configured with --enable-gpl --enable-libx264.

cd ~/ffmpeg_sources
git clone http://git.videolan.org/git/x264.git 
cd x264/
PATH="/opt/ffmpeg/bin:$PATH" ./configure --prefix="/opt/ffmpeg_build" --enable-static --enable-shared
PATH="/opt/ffmpeg/bin:$PATH" make -j$(nproc) VERBOSE=1
sudo make -j$(nproc) install VERBOSE=1
make -j$(nproc) distclean

(c ). Build and configure libx265: This library provides a H.265/HEVC video encoder. See the H.265 Encoding Guide for more information and usage examples.

cd ~/ffmpeg_sources
git clone https://bitbucket.org/multicoreware/x265_git.git
cd ~/ffmpeg_sources/x265/build/linux
PATH="/opt/ffmpeg/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="/opt/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
make -j$(nproc) VERBOSE=1
sudo make -j$(nproc) install VERBOSE=1
make -j$(nproc) clean VERBOSE=1

(d). Build and deploy the libfdk-aac library: This provides an AAC audio encoder. See the AAC Audio Encoding Guide for more information and usage examples. This requires ffmpeg to be configured with --enable-libfdk-aac (and --enable-nonfree if you also included --enable-gpl).

cd ~/ffmpeg_sources
wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master
tar xzvf fdk-aac.tar.gz
cd mstorsjo-fdk-aac*
autoreconf -fiv
./configure --prefix="/opt/ffmpeg_build" --disable-shared
make -j$(nproc)
sudo make -j$(nproc) install
make -j$(nproc) distclean

(e). Build and configure libvpx:

cd ~/ffmpeg_sources
git clone https://github.com/webmproject/libvpx
cd libvpx
./configure --prefix="/opt/ffmpeg_build" --enable-runtime-cpu-detect --enable-vp9 --enable-vp8 \
--enable-postproc --enable-vp9-postproc --enable-multi-res-encoding --enable-webm-io --enable-better-hw-compatibility --enable-vp9-highbitdepth --enable-onthefly-bitpacking --enable-realtime-only --cpu=native --as=nasm 
time make -j$(nproc)
sudo time make -j$(nproc) install
time make clean -j$(nproc)
time make distclean

(f). Build LibVorbis:

cd ~/ffmpeg_sources
git clone https://github.com/xiph/vorbis.git
cd vorbis
autoreconf -ivf
./configure --enable-static --prefix="/opt/ffmpeg_build"
time make -j$(nproc)
sudo make -j$(nproc) install
time make clean -j$(nproc)
time make distclean

Now add the new library path /opt/ffmpeg_build/lib to your ldconfig:

sudo su
echo /opt/ffmpeg_build/lib > /etc/ld.so.conf.d/ffmpeg.conf

Then run:

sudo ldconfig -vvvv

Then proceed.

(g). Build FFmpeg:

cd ~/ffmpeg_sources
git clone https://github.com/FFmpeg/FFmpeg -b master
cd FFmpeg
PATH="/opt/ffmpeg/bin:$PATH" PKG_CONFIG_PATH="/opt/ffmpeg_build/lib/pkgconfig" ./configure \
  --pkg-config-flags="--static" \
  --prefix="/opt/ffmpeg" \
  --bindir="/opt/ffmpeg/bin" \
  --extra-cflags="-I/opt/ffmpeg_build/include" \
  --extra-ldflags="-L/opt/ffmpeg_build/lib" \
  --enable-cuda-nvcc \
  --enable-cuvid \
  --enable-libnpp \
  --extra-cflags="-I/usr/local/cuda/include/" \
  --extra-ldflags=-L/usr/local/cuda/lib64/ \
  --enable-nvenc \
  --enable-libass \
  --disable-debug \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-opencl \
  --enable-gpl \
  --cpu=native \
  --enable-libfdk-aac \
  --enable-libx264 \
  --enable-libx265 \
  --enable-openssl \
  --enable-librtmp \
  --extra-libs="-lpthread -lm -lz" \
PATH="/opt/ffmpeg/bin:$PATH" make -j$(nproc) 
make -j$(nproc) install 
make -j$(nproc) distclean 
hash -r

Since we added /opt/ffmpeg/bin to the system path, you can call up FFmpeg directly.

  • That was amazing, thank you. Apr 18, 2020 at 13:19
  • You're welcome. Feel free to reach out if you need any help. Apr 20, 2020 at 19:24
  • So, there's a tiny hiccup. If you're on Ubuntu 19, you're gonna have GCC-9 defaulted, which CUDA 10.x doesn't support. It support GCC 8. Apr 21, 2020 at 15:13
  • And if you're not very smart with this stuff: linuxconfig.org/… can help you switch gcc version. Apr 21, 2020 at 19:22
  • 1
    Thanks for the detailed instructions, wouldn't have got there on my own. I worked through this on Ubuntu Server 20.04 and Cuda 11.2 and apart from a couple of filename and folder name differences all I needed to do was install ogg from github.com/xiph/ogg just before (f) Build LibVorbis and before configuring ffmpeg I edited the configuration file and changed compute_30 and sm_30 to compute_35 and sm_35 as the 30's are depreciated. 35's will probably be removed soon as well but as this is the compute power of my gpu's I've used it.
    – Mark
    Mar 20, 2021 at 11:53

In (f). Build LibVorbis:

https://git.xiph.org/vorbis.git change to https://github.com/xiph/vorbis.git

And also add to baseline dependencies:

libogg-dev, it needs by LibVorbis


In (c): Build and configure libx265
replace hg clone https://bitbucket.org/multicoreware/x265 by git clone https://bitbucket.org/multicoreware/x265_git.git is suitable for me.

And when installing the NVEnc, you can git clone other versions to fit your cuda version. like https://github.com/FFmpeg/nv-codec-headers/tree/sdk/9.0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.