Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
This gist will show you how to build a minimalist, statically-linked ffmpeg binary under the ~/bin subdirectory on your home on Ubuntu 16.04LTS. Comes with NPP, CUDA and NVENC capabilities.

Minimalist static FFmpeg build on Ubuntu 16.04 with Nvidia NVENC enabled.

Original guide with a standard build is here.

With this guide, I'm adding more instructions to enable support for NVIDIA CUVID and NVIDIA NPP for enhanced encode and decode performance.

First, prepare for the build and create the work space directory:

cd ~/
mkdir ~/ffmpeg_sources
sudo apt-get -y update && apt-get dist-upgrade -y
sudo apt-get -y install autoconf automake build-essential libass-dev \
  libtool \
  pkg-config texinfo zlib1g-dev cmake mercurial

Install CUDA 9.1 SDK from Nvidia's repository:

Note that this phase will prompt you to install the device driver. Skip it, and skip the samples too.We will install the driver later. Fetch the repository installers first:

cd ~/ffmpeg_sources

wget -c -v -nc http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb

sudo dpkg -i cuda-repo-ubuntu1604_9.1.85-1_amd64.deb

sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub

sudo apt-get update

sudo apt-get install cuda

Now, set up the environment variables for CUDA:

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

CUDA_HOME=/usr/local/cuda

Now, append the PATH variable with the following:

/usr/local/cuda/bin:$HOME/bin

When done, remember to source the file:

source /etc/environment

Build FFmpeg's dependency chain:

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're using the latest release candidate, and not the stable version as of the time of writing.

cd ~/ffmpeg_sources
wget http://www.nasm.us/pub/nasm/releasebuilds/2.14rc0/nasm-2.14rc0.tar.gz
tar xzvf nasm-2.14rc0.tar.gz
cd nasm-2.14rc0
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) distclean

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 -b stable
cd x264/
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --disable-opencl
PATH="$HOME/bin:$PATH" make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) distclean

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
hg clone https://bitbucket.org/multicoreware/x265
cd ~/ffmpeg_sources/x265/build/linux
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) clean

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="$HOME/ffmpeg_build" --disable-shared
make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) distclean

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

git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git
cd nv-codec-headers
make
sudo make install

Proceed as usual:

Building a static ffmpeg binary with the required options:

cd ~/ffmpeg_sources
git clone https://github.com/FFmpeg/FFmpeg -b master
cd FFmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --bindir="$HOME/bin" \
  --enable-cuda-sdk \
  --enable-cuvid \
  --enable-libnpp \
  --extra-cflags="-I/usr/local/cuda/include/" \
  --extra-ldflags=-L/usr/local/cuda/lib64/ \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nvenc \
  --enable-nonfree
PATH="$HOME/bin:$PATH" make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) distclean
hash -r

You may also want to tune your build further by calling upon NVCC to generate a build optimized for your GPU's CUDA architecture only.

The example below shows the build options to pass for Pascal's GM10x-series GPUs, with an SM version of 6.1:

cd ~/ffmpeg_sources
git clone https://github.com/FFmpeg/FFmpeg -b master
cd FFmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--static" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --bindir="$HOME/bin" \
  --enable-cuda-sdk \
  --enable-cuvid \
  --enable-libnpp \
  --extra-cflags="-I/usr/local/cuda/include/" \
  --extra-ldflags=-L/usr/local/cuda/lib64/ \
  --nvccflags="-gencode arch=compute_61,code=sm_61 -O2" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libx264 \
  --extra-libs=-lpthread \
  --enable-libx265 \
  --enable-nvenc \
  --enable-nonfree
PATH="$HOME/bin:$PATH" make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) distclean
hash -r

For the older Maxwell (GM204*-series) cards, the build below will generate optimized binaries for that CUDA architecture:

cd ~/ffmpeg_sources
git clone https://github.com/FFmpeg/FFmpeg -b master
cd FFmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure \
--prefix="$HOME/ffmpeg_build" \
--pkg-config-flags="--static" \
--extra-cflags="-I$HOME/ffmpeg_build/include" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \
--bindir="$HOME/bin" \
--enable-cuda \
--enable-cuvid \
--enable-libnpp \
--extra-cflags="-I/usr/local/cuda/include/" \
--extra-ldflags=-L/usr/local/cuda/lib64/ \
--nvccflags="-gencode arch=compute_52,code=sm_52 -O2" \
--enable-gpl \
--enable-libass \
--enable-libfdk-aac \
--enable-libx264 \
--enable-libx265 \
--extra-libs=-lpthread \
--enable-nvenc \
--enable-nonfree
PATH="$HOME/bin:$PATH" make -j$(nproc)
make -j$(nproc) install
make -j$(nproc) distclean
hash -r

Handling package upgrades:

For individual packages availed via git, simply navigate to their source directory and run git pull followed by re-building them:

(a). For nasm:

cd ~/ffmpeg_sources
git clone git://repo.or.cz/nasm.git
cd nasm
./autogen.sh
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"
make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) distclean

(b). For x264:

cd ~/ffmpeg_sources/x264
git pull
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-shared --disable-opencl
PATH="$HOME/bin:$PATH" make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) distclean

(c). For x265:

cd ~/ffmpeg_sources/x265
git pull
cd ~/ffmpeg_sources/x265/build/linux
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=on ../../source
make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) clean

(d). For the FFmpeg NVENC headers:

cd nv-codec-headers
git pull
make
sudo make install

(e). For FFmpeg:

i. For Pascal - based GPU systems (GP10x):

cd ~/ffmpeg_sources/FFmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig" ./configure \
  --prefix="$HOME/ffmpeg_build" \
  --pkg-config-flags="--shared" \
  --extra-cflags="-I$HOME/ffmpeg_build/include" \
  --extra-ldflags="-L$HOME/ffmpeg_build/lib" \
  --bindir="$HOME/bin" \
  --enable-cuda-sdk \
  --enable-cuvid \
  --enable-libnpp \
  --extra-cflags="-I/usr/local/cuda/include/" \
  --extra-ldflags=-L/usr/local/cuda/lib64/ \
  --nvccflags="-gencode arch=compute_61,code=sm_61 -O2" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libx264 \
  --extra-libs=-lpthread \
  --enable-libx265 \
  --enable-nvenc \
  --enable-nonfree
PATH="$HOME/bin:$PATH" make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) distclean
hash -r

ii. For Maxwell (GM20x-based Tesla systems):

cd ~/ffmpeg_sources/FFmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig" ./configure \
--prefix="$HOME/ffmpeg_build" \
--extra-cflags="-I$HOME/ffmpeg_build/include" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib" \
--bindir="$HOME/bin" \
--enable-cuda \
--enable-cuvid \
--enable-libnpp \
--extra-cflags="-I/usr/local/cuda/include/" \
--extra-ldflags=-L/usr/local/cuda/lib64/ \
--nvccflags="-gencode arch=compute_52,code=sm_52 -O2" \
--enable-gpl \
--enable-libass \
--enable-libfdk-aac \
--enable-libx264 \
--enable-libx265 \
--extra-libs=-lpthread \
--enable-nvenc \
--enable-nonfree
PATH="$HOME/bin:$PATH" make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) distclean
hash -r

On nasm:

We build nasm from source, using the git master tip as it contains the latest assembler optimizations for modern processor architectures. When considering subsequent updates to FFmpeg, consider switching to the git clone rather than the tarball fetched from nasm.us. However, we retain both versions for assembler testing and compatibility, should the master tip version fail to build due to compiler errors and warnings.

Confirm that all GPUs are working:

nvidia-smi -q | grep Encoder | wc -l

This should return the number of GPUs present , and in the case of the dual Tesla M60s, based on the GM204GL SKUs, expect the number to be 4 on a dual-GPU system as each card has a single NVENC chip per graphics processor.

Note that on newer platforms (such as the Nvidia Pascal P1000), the number of NVENC chips per GPU may vary, and may be up to 3 per GPU, totalling to six per Tesla board. See the GPU support matrix for more information.

If ~/bin is already in your path, you can call up ffmpeg directly. Note that the build instructions assume that the NVIDIA CUDA toolkit is on the system path, as is recommended during setup.

Hint: Use this guide to learn how to launch ffmpeg in multiple instances for faster NVENC based encoding on capable hardware.

@llogan

This comment has been minimized.

Show comment Hide comment
@llogan

llogan Dec 10, 2016

16.04 provides yasm 1.3.0 so you can just install it from the repo instead of compiling. The Ubuntu compile guide on the FFmpeg Wiki that you adapted (an attribution link would be appreciated as it is covered by CC BY-SA 3.0) has users compile it because that guide is intended to be usable with all supported Ubuntu versions. Once you use the repo yasm you can, IIRC, avoid using the PATH="$HOME/bin:$PATH" instances.

Secondly, are you sure you need to download the NVENC SDK? I could be mistaken, but I think it and CUDA stuff are included in the FFmpeg source in the compat directory.

llogan commented Dec 10, 2016

16.04 provides yasm 1.3.0 so you can just install it from the repo instead of compiling. The Ubuntu compile guide on the FFmpeg Wiki that you adapted (an attribution link would be appreciated as it is covered by CC BY-SA 3.0) has users compile it because that guide is intended to be usable with all supported Ubuntu versions. Once you use the repo yasm you can, IIRC, avoid using the PATH="$HOME/bin:$PATH" instances.

Secondly, are you sure you need to download the NVENC SDK? I could be mistaken, but I think it and CUDA stuff are included in the FFmpeg source in the compat directory.

@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 Dec 18, 2016

Yes, the NVENC SDK is needed, in full.

Owner

Brainiarc7 commented Dec 18, 2016

Yes, the NVENC SDK is needed, in full.

@unrelatedlabs

This comment has been minimized.

Show comment Hide comment
@unrelatedlabs

unrelatedlabs Dec 28, 2016

Had to include lib path to cuda, otherwise libnpp was not found.

Adding --extra-cflags="-I/usr/local/cuda/include/" --extra-ldflags=-L/usr/local/cuda/lib64/ to configure

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --pkg-config-flags="--static" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --enable-cuda --enable-cuvid --enable-libnpp --extra-cflags=-I../nv_sdk --extra-ldflags=-L../nv_sdk --enable-gpl --enable-libass --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-nvenc --enable-nonfree --extra-cflags="-I/usr/local/cuda/include/" --extra-ldflags=-L/usr/local/cuda/lib64/

unrelatedlabs commented Dec 28, 2016

Had to include lib path to cuda, otherwise libnpp was not found.

Adding --extra-cflags="-I/usr/local/cuda/include/" --extra-ldflags=-L/usr/local/cuda/lib64/ to configure

PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --pkg-config-flags="--static" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --enable-cuda --enable-cuvid --enable-libnpp --extra-cflags=-I../nv_sdk --extra-ldflags=-L../nv_sdk --enable-gpl --enable-libass --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-nvenc --enable-nonfree --extra-cflags="-I/usr/local/cuda/include/" --extra-ldflags=-L/usr/local/cuda/lib64/

@freezy

This comment has been minimized.

Show comment Hide comment
@freezy

freezy Mar 23, 2017

I had to add --enable-shared to the x264 configuration, otherwise I had linker errors.

freezy commented Mar 23, 2017

I had to add --enable-shared to the x264 configuration, otherwise I had linker errors.

@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 Mar 28, 2017

Hello @unrelatedlabs,

Thanks for the correction above.

I also ran into the same problem with the current NVENC SDK version (v7.1.9), your fix corrects the problem.

Updating the documentation now.

Owner

Brainiarc7 commented Mar 28, 2017

Hello @unrelatedlabs,

Thanks for the correction above.

I also ran into the same problem with the current NVENC SDK version (v7.1.9), your fix corrects the problem.

Updating the documentation now.

@vidiben

This comment has been minimized.

Show comment Hide comment
@vidiben

vidiben Apr 7, 2017

Hi, on lubuntu 16.04, I am running into the following issues

  1. NPP: the configure command keeps complaining, saying it cannot find libnpp.

I don't have any cuda folder in /usr/local (using a fresh lubuntu 16.04 setup), but it looks to be properly installed.

# find /usr/lib/x86_64-linux-gnu/ -name "*npp*"
/usr/lib/x86_64-linux-gnu/libnpps.so
/usr/lib/x86_64-linux-gnu/libnppi.so.7.5.18
/usr/lib/x86_64-linux-gnu/libnpps_static.a
/usr/lib/x86_64-linux-gnu/libnppc_static.a
/usr/lib/x86_64-linux-gnu/libnppc.so.7.5
/usr/lib/x86_64-linux-gnu/libnppi.so
/usr/lib/x86_64-linux-gnu/libnpps.so.7.5.18
/usr/lib/x86_64-linux-gnu/libnppi_static.a
/usr/lib/x86_64-linux-gnu/libnppi.so.7.5
/usr/lib/x86_64-linux-gnu/libnpps.so.7.5
/usr/lib/x86_64-linux-gnu/stubs/libnpps.so
/usr/lib/x86_64-linux-gnu/stubs/libnppi.so
/usr/lib/x86_64-linux-gnu/stubs/libnppc.so
/usr/lib/x86_64-linux-gnu/libnppc.so
/usr/lib/x86_64-linux-gnu/libnppc.so.7.5.18

@unrelatedlabs, @Brainiarc7: Where and how can I get a local build of cuda to link to?

  1. When I disable libnpp, I can compile but each time I try to use nvenc, I am getting a Segmentation fault. Same result if cuda and cuvid are disabled :\
ffmpeg -i tmp.0.h264 -c:v hevc_nvenc test.mkv                                            Moviez/Ghost in the Shell (1995).tmp.mkv grospc
ffmpeg version N-85328-g8d94d97 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --prefix=/tmp/ffmpeg/build --pkg-config-flags=--static --extra-cflags='-I/tmp/ffmpeg/build/include -static' --extra-ldflags='-L/tmp/ffmpeg/build/lib -static' --bindir=/usr/local/bin --extra-cflags=-I/tmp/ffmpeg/sources/nv_sdk --extra-ldflags=-L/tmp/ffmpeg/sources/nv_sdk --enable-gpl --extra-ldflags=-L/usr/lib/x86_64-linux-gnu/ --enable-libass --enable-libfdk-aac --enable-vaapi --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree --enable-nvenc --enable-static --disable-ffplay --disable-ffserver --disable-shared --enable-debug --enable-cuda --enable-cuvid
  libavutil      55. 60.100 / 55. 60.100
  libavcodec     57. 92.100 / 57. 92.100
  libavformat    57. 72.100 / 57. 72.100
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 84.100 /  6. 84.100
  libswscale      4.  7.100 /  4.  7.100
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
Input #0, h264, from 'tmp.0.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1040, 23.98 fps, 23.98 tbr, 1200k tbn, 47.95 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> hevc (hevc_nvenc))
Press [q] to stop, [?] for help
[1]    12775 segmentation fault (core dumped)  ffmpeg -i tmp.0.h264 -c:v hevc_nvenc test.mkv

vidiben commented Apr 7, 2017

Hi, on lubuntu 16.04, I am running into the following issues

  1. NPP: the configure command keeps complaining, saying it cannot find libnpp.

I don't have any cuda folder in /usr/local (using a fresh lubuntu 16.04 setup), but it looks to be properly installed.

# find /usr/lib/x86_64-linux-gnu/ -name "*npp*"
/usr/lib/x86_64-linux-gnu/libnpps.so
/usr/lib/x86_64-linux-gnu/libnppi.so.7.5.18
/usr/lib/x86_64-linux-gnu/libnpps_static.a
/usr/lib/x86_64-linux-gnu/libnppc_static.a
/usr/lib/x86_64-linux-gnu/libnppc.so.7.5
/usr/lib/x86_64-linux-gnu/libnppi.so
/usr/lib/x86_64-linux-gnu/libnpps.so.7.5.18
/usr/lib/x86_64-linux-gnu/libnppi_static.a
/usr/lib/x86_64-linux-gnu/libnppi.so.7.5
/usr/lib/x86_64-linux-gnu/libnpps.so.7.5
/usr/lib/x86_64-linux-gnu/stubs/libnpps.so
/usr/lib/x86_64-linux-gnu/stubs/libnppi.so
/usr/lib/x86_64-linux-gnu/stubs/libnppc.so
/usr/lib/x86_64-linux-gnu/libnppc.so
/usr/lib/x86_64-linux-gnu/libnppc.so.7.5.18

@unrelatedlabs, @Brainiarc7: Where and how can I get a local build of cuda to link to?

  1. When I disable libnpp, I can compile but each time I try to use nvenc, I am getting a Segmentation fault. Same result if cuda and cuvid are disabled :\
ffmpeg -i tmp.0.h264 -c:v hevc_nvenc test.mkv                                            Moviez/Ghost in the Shell (1995).tmp.mkv grospc
ffmpeg version N-85328-g8d94d97 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 20160609
  configuration: --prefix=/tmp/ffmpeg/build --pkg-config-flags=--static --extra-cflags='-I/tmp/ffmpeg/build/include -static' --extra-ldflags='-L/tmp/ffmpeg/build/lib -static' --bindir=/usr/local/bin --extra-cflags=-I/tmp/ffmpeg/sources/nv_sdk --extra-ldflags=-L/tmp/ffmpeg/sources/nv_sdk --enable-gpl --extra-ldflags=-L/usr/lib/x86_64-linux-gnu/ --enable-libass --enable-libfdk-aac --enable-vaapi --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree --enable-nvenc --enable-static --disable-ffplay --disable-ffserver --disable-shared --enable-debug --enable-cuda --enable-cuvid
  libavutil      55. 60.100 / 55. 60.100
  libavcodec     57. 92.100 / 57. 92.100
  libavformat    57. 72.100 / 57. 72.100
  libavdevice    57.  7.100 / 57.  7.100
  libavfilter     6. 84.100 /  6. 84.100
  libswscale      4.  7.100 /  4.  7.100
  libswresample   2.  8.100 /  2.  8.100
  libpostproc    54.  6.100 / 54.  6.100
Input #0, h264, from 'tmp.0.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (High), yuv420p(progressive), 1920x1040, 23.98 fps, 23.98 tbr, 1200k tbn, 47.95 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> hevc (hevc_nvenc))
Press [q] to stop, [?] for help
[1]    12775 segmentation fault (core dumped)  ffmpeg -i tmp.0.h264 -c:v hevc_nvenc test.mkv
@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 Apr 16, 2017

Hello @vidiben,

It would be best to install CUDA SDK 8 from Nvidia's repository.

I'll update this gist with these instructions soon.

Owner

Brainiarc7 commented Apr 16, 2017

Hello @vidiben,

It would be best to install CUDA SDK 8 from Nvidia's repository.

I'll update this gist with these instructions soon.

@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 Apr 19, 2017

Hello @vidiben,

It's done.

Owner

Brainiarc7 commented Apr 19, 2017

Hello @vidiben,

It's done.

@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 May 8, 2017

Hello @vibiden,

How did you install CUDA when you got the segmentation faults?

Owner

Brainiarc7 commented May 8, 2017

Hello @vibiden,

How did you install CUDA when you got the segmentation faults?

@croepha

This comment has been minimized.

Show comment Hide comment
@croepha

croepha Jun 21, 2017

i had to install nasm from source, libx264 kept complaining about my yasm source

croepha commented Jun 21, 2017

i had to install nasm from source, libx264 kept complaining about my yasm source

@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 Jun 25, 2017

Hello @croepha,

Your observation is correct.

x264 and others are now favoring nasm over yasm, will correct the gist with this information. Thanks for the feedback!

Owner

Brainiarc7 commented Jun 25, 2017

Hello @croepha,

Your observation is correct.

x264 and others are now favoring nasm over yasm, will correct the gist with this information. Thanks for the feedback!

@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 Jun 26, 2017

And now updated with new build options and flags that need to be passed so as to generate optimized kernels for the specific GPU architecture.

Owner

Brainiarc7 commented Jun 26, 2017

And now updated with new build options and flags that need to be passed so as to generate optimized kernels for the specific GPU architecture.

@libero08

This comment has been minimized.

Show comment Hide comment
@libero08

libero08 Jul 3, 2017

Hi B7,
as you knew i'm a follower of youre tips and tutorials.
Unfortunately, the new "minimalistic buld for nvenc" cause me lot of problem during the instalation process.
first step:
i install a fresh & clean ubuntu 16.04
i install all step by step and all goes fine untill here:
"sudo systemctl reboot"
After reboot
a lot of probblems begin!
i loose environment for the sistem, even inside the file /etc/environement this line was unmodified:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
i was forced to modiffied on this way to make system work again:
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
and inside of environmet i have also included this 2 lines like you say before:
export CUDA_HOME=/usr/local/cuda-8.0
export PATH=/usr/local/cuda/bin:$PATH
The problems do not stop here.
The system stuckt here durinfg the compilation of ffmpeg -here : make -j$(nproc), because it was unable to link to the "nvcc" on /usr/local/cuda/bin" or /usr/local/cuda-8.0/bin"!
To make proper system work and i install also " libproc-processtable-perl"
and for revealing nvcc ( i was unable to reveal using which and nvcc -V return nothing) i was forced to install: apt install nvidia-cuda-toolkit
after that i was able to compile ffmpeg.
Sincerly don't knew yet if cuda works, but calling during encoder processo of libx264 ffmpeg do his job.
I enable also on my binary libfreetype.
So, please moddify when you can with corect arguments the instalation steps.

libero08 commented Jul 3, 2017

Hi B7,
as you knew i'm a follower of youre tips and tutorials.
Unfortunately, the new "minimalistic buld for nvenc" cause me lot of problem during the instalation process.
first step:
i install a fresh & clean ubuntu 16.04
i install all step by step and all goes fine untill here:
"sudo systemctl reboot"
After reboot
a lot of probblems begin!
i loose environment for the sistem, even inside the file /etc/environement this line was unmodified:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
i was forced to modiffied on this way to make system work again:
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
and inside of environmet i have also included this 2 lines like you say before:
export CUDA_HOME=/usr/local/cuda-8.0
export PATH=/usr/local/cuda/bin:$PATH
The problems do not stop here.
The system stuckt here durinfg the compilation of ffmpeg -here : make -j$(nproc), because it was unable to link to the "nvcc" on /usr/local/cuda/bin" or /usr/local/cuda-8.0/bin"!
To make proper system work and i install also " libproc-processtable-perl"
and for revealing nvcc ( i was unable to reveal using which and nvcc -V return nothing) i was forced to install: apt install nvidia-cuda-toolkit
after that i was able to compile ffmpeg.
Sincerly don't knew yet if cuda works, but calling during encoder processo of libx264 ffmpeg do his job.
I enable also on my binary libfreetype.
So, please moddify when you can with corect arguments the instalation steps.

@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 Jul 5, 2017

Hello @libero08 ,

I'm sorry to hear that you're having problems with these instructions.

However, note that before I publish any of these gists, great effort is made to ensure that:

(a). The testbed is always running the latest, greatest version of Ubuntu LTS, confirmed by running apt-get upgrade and apt-get dist-upgrade.
(b). Unless otherwise specified, the NVIDIA CUDA SDK's installation process detailed above also installs the appropriate Nvidia driver, and the CUDA toolkit's binaries, which, by default, are not in the system path. This is why we modify these environment variables to set both CUDA_HOME and prepend the PATH variable with the location for the CUDA-8 SDK's bin subdirectory, as demonstrated above.

From the symptoms observed, it can be concluded that you did not use an up to date Ubuntu installation.
Even after installing a new installation from an Ubuntu installation image (boot media), you must run:

sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get dist-upgrade -y
To ensure that you're running the latest kernel (see the last dist-upgrade part).

You may want to retry the build with a clean slate. A verification of these build steps produces a working ffmpeg binary.

Owner

Brainiarc7 commented Jul 5, 2017

Hello @libero08 ,

I'm sorry to hear that you're having problems with these instructions.

However, note that before I publish any of these gists, great effort is made to ensure that:

(a). The testbed is always running the latest, greatest version of Ubuntu LTS, confirmed by running apt-get upgrade and apt-get dist-upgrade.
(b). Unless otherwise specified, the NVIDIA CUDA SDK's installation process detailed above also installs the appropriate Nvidia driver, and the CUDA toolkit's binaries, which, by default, are not in the system path. This is why we modify these environment variables to set both CUDA_HOME and prepend the PATH variable with the location for the CUDA-8 SDK's bin subdirectory, as demonstrated above.

From the symptoms observed, it can be concluded that you did not use an up to date Ubuntu installation.
Even after installing a new installation from an Ubuntu installation image (boot media), you must run:

sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get dist-upgrade -y
To ensure that you're running the latest kernel (see the last dist-upgrade part).

You may want to retry the build with a clean slate. A verification of these build steps produces a working ffmpeg binary.

@libero08

This comment has been minimized.

Show comment Hide comment
@libero08

libero08 Jul 5, 2017

Shure i do!
Beacause i read careffuly all instruction from cuda (PDF) and i found a lot of thing verry interesting.
I supose it' was my fault 100%.
BTW i found some new instruction of cuda incompatible with my device.
Can you permit me to send you an e-mail from gist or git ?

libero08 commented Jul 5, 2017

Shure i do!
Beacause i read careffuly all instruction from cuda (PDF) and i found a lot of thing verry interesting.
I supose it' was my fault 100%.
BTW i found some new instruction of cuda incompatible with my device.
Can you permit me to send you an e-mail from gist or git ?

@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 Jul 5, 2017

Sure, navigate to my profile and send me an email to that address.

Owner

Brainiarc7 commented Jul 5, 2017

Sure, navigate to my profile and send me an email to that address.

@hydra3333

This comment has been minimized.

Show comment Hide comment
@hydra3333

hydra3333 Aug 7, 2017

Thank you for this good information.
I am attempting to use rdp's cross-compile script in ububtu 17.04 with gcc7.1.0 to produce a static windows ffmpeg executable.
I'm still hazy on what to download from nvidia and cross-compile and what switches to use, to enable these.
scale_cuda
scale_npp
For example this "--extra-ldflags=-L/usr/local/cuda/lib64/" seems to imply that libnpp has to be cross-compiled from source too.
I see the latest ffmpeg git has a "--enable-cuda-sdk" build switch, but am not sure what that implies in regard to downloading things and cross-compiling.
I'm unclear though what that means in order to build filter scale_cuda and what relationship scale_cuda has to scale_npp (the scale_cuda source is in the ffmpeg git).
Any advice would be greatly appreciated.

Thank you for this good information.
I am attempting to use rdp's cross-compile script in ububtu 17.04 with gcc7.1.0 to produce a static windows ffmpeg executable.
I'm still hazy on what to download from nvidia and cross-compile and what switches to use, to enable these.
scale_cuda
scale_npp
For example this "--extra-ldflags=-L/usr/local/cuda/lib64/" seems to imply that libnpp has to be cross-compiled from source too.
I see the latest ffmpeg git has a "--enable-cuda-sdk" build switch, but am not sure what that implies in regard to downloading things and cross-compiling.
I'm unclear though what that means in order to build filter scale_cuda and what relationship scale_cuda has to scale_npp (the scale_cuda source is in the ffmpeg git).
Any advice would be greatly appreciated.

@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 Aug 12, 2017

Here is what you will need:

  1. The whole CUDA 8 SDK. Some people use the repository method to install it, but I personally recommend using the runfile installer as it allows you to skip the device driver. However, this method requires a few manual steps, such as setting up a custom ld.so.conf.d/*.conf entry for the NVIDIA CUDA SDK libraries prior to usage.

  2. The scale_cuda filter is somewhat analogous to the options offered by the scale_npp filter, with a few differences: The first one is automatically built when the --enable-cuda-sdk option is used, whereas the latter can only be enabled and built after the --enable-libnpp option is passed, combined with the --enable-cuda-sdk option as a dependency.

You can learn more about Nvidia's Performance Primitives libraries here and from the documentation.

Follow this gist for what's available with NPP and NVENC for FFmpeg, when these options are enabled.

Owner

Brainiarc7 commented Aug 12, 2017

Here is what you will need:

  1. The whole CUDA 8 SDK. Some people use the repository method to install it, but I personally recommend using the runfile installer as it allows you to skip the device driver. However, this method requires a few manual steps, such as setting up a custom ld.so.conf.d/*.conf entry for the NVIDIA CUDA SDK libraries prior to usage.

  2. The scale_cuda filter is somewhat analogous to the options offered by the scale_npp filter, with a few differences: The first one is automatically built when the --enable-cuda-sdk option is used, whereas the latter can only be enabled and built after the --enable-libnpp option is passed, combined with the --enable-cuda-sdk option as a dependency.

You can learn more about Nvidia's Performance Primitives libraries here and from the documentation.

Follow this gist for what's available with NPP and NVENC for FFmpeg, when these options are enabled.

@hydra3333

This comment has been minimized.

Show comment Hide comment
@hydra3333

hydra3333 Aug 14, 2017

Thank you.

The whole CUDA 8 SDK. Some people use the repository method to install it, but I personally recommend using the runfile installer as it allows you to skip the device driver. However, this method requires a few manual steps, such as setting up a custom ld.so.conf.d/*.conf entry for the NVIDIA CUDA SDK libraries prior to usage.

I'm not sure how to do a "few manual steps, such as setting up a custom ld.so.conf.d/*.conf entry for the NVIDIA CUDA SDK libraries prior to usage", for the static build cross-compilation.

Thank you.

The whole CUDA 8 SDK. Some people use the repository method to install it, but I personally recommend using the runfile installer as it allows you to skip the device driver. However, this method requires a few manual steps, such as setting up a custom ld.so.conf.d/*.conf entry for the NVIDIA CUDA SDK libraries prior to usage.

I'm not sure how to do a "few manual steps, such as setting up a custom ld.so.conf.d/*.conf entry for the NVIDIA CUDA SDK libraries prior to usage", for the static build cross-compilation.

@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 Aug 14, 2017

I'll update the gist with instructions for the same.

Owner

Brainiarc7 commented Aug 14, 2017

I'll update the gist with instructions for the same.

@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 Aug 16, 2017

Done.

Owner

Brainiarc7 commented Aug 16, 2017

Done.

@xseignard

This comment has been minimized.

Show comment Hide comment
@xseignard

xseignard Sep 4, 2017

Hello @Brainiarc7

First of all thanks for your guide,
I'd like to know if this gist is still up to date?

Regards

Hello @Brainiarc7

First of all thanks for your guide,
I'd like to know if this gist is still up to date?

Regards

@PMLavigne

This comment has been minimized.

Show comment Hide comment
@PMLavigne

PMLavigne Oct 4, 2017

Unless I'm missing something, there's no such ffmpeg build flag as "--enable-cuda-sdk", there's just "--enable-cuda". Maybe they dropped it/changed it recently?

Unless I'm missing something, there's no such ffmpeg build flag as "--enable-cuda-sdk", there's just "--enable-cuda". Maybe they dropped it/changed it recently?

@Brainiarc7

This comment has been minimized.

Show comment Hide comment
@Brainiarc7

Brainiarc7 Oct 5, 2017

Yes, @PMLavigne,

The build flag was dropped in place of the current one.

Owner

Brainiarc7 commented Oct 5, 2017

Yes, @PMLavigne,

The build flag was dropped in place of the current one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment