Instantly share code, notes, and snippets.

Embed
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 (optiona) NPP, CUDA and NVENC capabilities. See notes in the warning section.

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.

Warning:

If all you require is NVENC's enablement, you do NOT need the CUDA SDK. The nv-codec-headers (below) is ALL you require. However, the SDK is needed IF, and only IF, the usage of the scale_npp and any other CUDA-based filters is required.

With that in mind, do note that the NVIDIA proprietary driver is mandatory. See the driver setup instructions below, and the warning notes for Ubuntu 18.04LTS.

Steps:

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.2 SDK from Nvidia's repository:

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, this should be enough for the device driver:

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

We keep the device driver up to the latest version so as to pass FFmpeg's NVENC driver version check.

Fetch the repository installers first:

cd ~/ffmpeg_sources

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

sudo dpkg -i cuda-repo-ubuntu1604_9.2.148-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

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

/etc/ld.so.conf.d/cuda.conf

The content should be:

/usr/local/cuda/lib64

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:

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 https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/nasm-2.13.03.tar.xz
tar xzvf nasm-2.13.03.tar.gz
cd nasm-2.13.03
./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 --enable-shared --disable-opencl
PATH="$HOME/bin:$PATH" make -j$(nproc) VERBOSE=1
make -j$(nproc) install
make -j$(nproc) distclean

Note: If you need to enable OpenCL support for either libx264 or FFmpeg, ensure that:

(a). The flag --disable-opencl is removed from libx264's configuration.

(b). The flag enable-opencl is present in FFmpeg's configure options.

(c ). The prerequisite packages for OpenCL development are present:

With OpenCL, the installable client drivers (ICDs) are normally issued with the accelerator's device drivers, namely:

  1. The NVIDIA CUDA toolkit (and the device driver) for NVIDIA GPUs.
  2. AMD's RoCM for GCN-class AMD hardware.
  3. Intel's beignet and the newer Neo compute runtime.

The purpose of the installable client driver model is to allow multiple OpenCL platforms to coexist on the same platform. That way, multiple OpenCL accelerators, be they discrete GPUs paired with a combination of FPGAs and integrated GPUs can all coexist.

However, for linkage purposes, you'll require the ocl-icd package, which can be installed by:

sudo apt install ocl-icd-* 

Why ocl-icd? Simple: Whereas other ICDs may permit you to link against them directly, it is discouraged so as to limit the risk of unexpected runtime behavior. Assume ocl-icd to be the gold link target if your goal is to be platform-neutral as possible.

OpenCL in FFmpeg:

OpenCL's enablement in FFmpeg comes in two ways:

(a):. Some encoders, such as libx264, if built with OpenCL enablement, can utilize these capabilities for accelerated lookahead functions. The performance impact for this enablement will vary with the GPU on the platform, and with older GPUs, may slow down the encoder. Lower power platforms such as specific AMD APUs and their SoCs may see modest performance improvements at best, but on modern, high performance GPUs, your mileage may vary. Expect no miracles. The reason OpenCL lookahead is available for this library in particular is that the lookahead algorithms for OpenCL are easily parallelized.

For instance, you can combine the -hwaccel auto option which allows you to select the hardware-based accelerated decoding to use for the encode session with libx264. You can add this parameter with "auto" before input (if your x264 is compiled with OpenCL support you can try to add -x264opts param), for example:

ffmpeg -hwaccel auto -i input -vcodec libx264 -x264opts opencl output

(b):. FFmpeg, in particular, can utilize OpenCL with some filters, namely program_opencl and opencl_src as documented in the filters documentation, among others.

See the sample command below:

ffmpeg -hide_banner -v verbose -init_hw_device 
opencl=ocl:1.0 -filter_hw_device ocl -i 
"cheeks.mkv" -an -map_metadata -1 -sws_flags 
lanczos+accurate_rnd+full_chroma_int+full_chroma_inp -filter_complex 
"[0:v]yadif=0:0:0,hwupload,unsharp_opencl=lx=3:ly=3:la=0.5:cx=3:cy=3:ca=0.5,hwdownload,setdar=dar=16/9" 
 -r 25 -c:v h264_nvenc -preset:v llhq -bf 2 -g 50 -refs 3 -rc:v 
vbr_hq -rc-lookahead:v 32 -coder:v cabac -movflags 
+faststart -profile:v high -level 4.1 -pixel_format yuv420p -y 
".crunchy_cheeks.mp4"

List OpenCL platform devices:

ffmpeg -hide_banner -v verbose -init_hw_device list
ffmpeg -hide_banner -v verbose -init_hw_device opencl
ffmpeg -hide_banner -v verbose -init_hw_device opencl:1.0 

For the filter, see:

ffmpeg -hide_banner -v verbose -h filter=unsharp_opencl 

Bonus score: If you're adventurous, you could also try out this OpenCL build of libvpx from Ittiam systems, especially if you're using Integrated graphics or an FPGA (Xilinx).

Carrying on:

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:

cd ~/ffmpeg_sources
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

Remember the notes above on builds that do not require any CUDA-based filters? This build below will give you exactly that:

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-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

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
hg pull
hg update
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
git pull
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
git pull
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

  1. An FFmpeg build with NVENC only (without CUDA dependencies):
cd ~/ffmpeg_sources/FFmpeg
git pull
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-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

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.

hydra3333 commented 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.

@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.

hydra3333 commented 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.

@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
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

xseignard commented 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

@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?

PMLavigne commented 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?

@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.

@RobHumphris

This comment has been minimized.

Show comment
Hide comment
@RobHumphris

RobHumphris May 25, 2018

Most recently (version.sh reports VERSION " r2901 7d0ff22") I have had to configure x264 with:
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --enable-pic --disable-opencl

or I get an error at link time and a number of messages saying to recompile with -fPIC option.

RobHumphris commented May 25, 2018

Most recently (version.sh reports VERSION " r2901 7d0ff22") I have had to configure x264 with:
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static --enable-pic --disable-opencl

or I get an error at link time and a number of messages saying to recompile with -fPIC option.

@Brainiarc7

This comment has been minimized.

Show comment
Hide comment
@Brainiarc7

Brainiarc7 May 28, 2018

Hello @RobHumphris,

I've made changes to the x264 build steps above. Retest.

Owner

Brainiarc7 commented May 28, 2018

Hello @RobHumphris,

I've made changes to the x264 build steps above. Retest.

@minostauros

This comment has been minimized.

Show comment
Hide comment
@minostauros

minostauros May 29, 2018

Thanks for an amazing guide.
Though it builds well, I cannot build OpenCV 3.4.1 with this build of FFmpeg. Any ideas?

CMake Error at cmake/OpenCVFindLibsVideo.cmake:239 (message):
  FFMPEG: test check build log:

  Change Dir: /hello/opencv-3.4.1/build/CMakeFiles/CMakeTmp

  

  Run Build Command:"/usr/bin/make" "cmTC_0d034/fast"

  /usr/bin/make -f CMakeFiles/cmTC_0d034.dir/build.make
  CMakeFiles/cmTC_0d034.dir/build

  make[1]: Entering directory '/hello/opencv-3.4.1/build/CMakeFiles/CMakeTmp'

  Building CXX object CMakeFiles/cmTC_0d034.dir/ffmpeg_test.cpp.o

  /usr/bin/c++ -I/root/ffmpeg_build/include -I/usr/include/x86_64-linux-gnu
  -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor
  -Werror=address -Werror=sequence-point -Wformat -Werror=format-security
  -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow
  -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing
  -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option
  -Wno-long-long -pthread -fomit-frame-pointer -ffast-math
  -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden
  -fvisibility-inlines-hidden -O3 -DNDEBUG -fPIE -o
  CMakeFiles/cmTC_0d034.dir/ffmpeg_test.cpp.o -c
  /hello/opencv-3.4.1/cmake/checks/ffmpeg_test.cpp

  Linking CXX executable cmTC_0d034

  /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_0d034.dir/link.txt
  --verbose=1

  /usr/bin/c++ -fsigned-char -W -Wall -Werror=return-type
  -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat
  -Werror=format-security -Wmissing-declarations -Wundef -Winit-self
  -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self
  -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment
  -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer
  -ffast-math -ffunction-sections -fdata-sections -msse -msse2 -msse3
  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG
  -Wl,--gc-sections CMakeFiles/cmTC_0d034.dir/ffmpeg_test.cpp.o -o cmTC_0d034
  -L/root/ffmpeg_build/lib -rdynamic -lavformat -lm -lz -lavcodec -lvpx
  -lpthread -lfdk-aac -lmp3lame -lopus -ltheoraenc -ltheoradec -logg -lvorbis
  -lvorbisenc -lx264 -ldl -lx265 -lstdc++ -lrt -lnuma -lva -lswresample
  -lswscale -lavutil -lva-drm -lva-x11 -lX11 -lvdpau -lavresample-ffmpeg
  -Wl,-rpath,/root/ffmpeg_build/lib

  /root/ffmpeg_build/lib/libavcodec.a(tiff.o): In function
  `tiff_uncompress_lzma':

  /root/ffmpeg_sources/FFmpeg/libavcodec/tiff.c:398: undefined reference to
  `lzma_stream_decoder'

  /root/ffmpeg_sources/FFmpeg/libavcodec/tiff.c:403: undefined reference to
  `lzma_code'

  /root/ffmpeg_sources/FFmpeg/libavcodec/tiff.c:404: undefined reference to
  `lzma_end'

  collect2: error: ld returned 1 exit status

  CMakeFiles/cmTC_0d034.dir/build.make:97: recipe for target 'cmTC_0d034'
  failed

  make[1]: *** [cmTC_0d034] Error 1

  make[1]: Leaving directory '/hello/opencv-3.4.1/build/CMakeFiles/CMakeTmp'

  Makefile:126: recipe for target 'cmTC_0d034/fast' failed

  make: *** [cmTC_0d034/fast] Error 2

Call Stack (most recent call first):
  CMakeLists.txt:636 (include)

Seems like -llzma is missing in cmake's point of view of ${FFMPEG_LIBRARIES} .

minostauros commented May 29, 2018

Thanks for an amazing guide.
Though it builds well, I cannot build OpenCV 3.4.1 with this build of FFmpeg. Any ideas?

CMake Error at cmake/OpenCVFindLibsVideo.cmake:239 (message):
  FFMPEG: test check build log:

  Change Dir: /hello/opencv-3.4.1/build/CMakeFiles/CMakeTmp

  

  Run Build Command:"/usr/bin/make" "cmTC_0d034/fast"

  /usr/bin/make -f CMakeFiles/cmTC_0d034.dir/build.make
  CMakeFiles/cmTC_0d034.dir/build

  make[1]: Entering directory '/hello/opencv-3.4.1/build/CMakeFiles/CMakeTmp'

  Building CXX object CMakeFiles/cmTC_0d034.dir/ffmpeg_test.cpp.o

  /usr/bin/c++ -I/root/ffmpeg_build/include -I/usr/include/x86_64-linux-gnu
  -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor
  -Werror=address -Werror=sequence-point -Wformat -Werror=format-security
  -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow
  -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing
  -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option
  -Wno-long-long -pthread -fomit-frame-pointer -ffast-math
  -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden
  -fvisibility-inlines-hidden -O3 -DNDEBUG -fPIE -o
  CMakeFiles/cmTC_0d034.dir/ffmpeg_test.cpp.o -c
  /hello/opencv-3.4.1/cmake/checks/ffmpeg_test.cpp

  Linking CXX executable cmTC_0d034

  /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_0d034.dir/link.txt
  --verbose=1

  /usr/bin/c++ -fsigned-char -W -Wall -Werror=return-type
  -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat
  -Werror=format-security -Wmissing-declarations -Wundef -Winit-self
  -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self
  -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment
  -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer
  -ffast-math -ffunction-sections -fdata-sections -msse -msse2 -msse3
  -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG
  -Wl,--gc-sections CMakeFiles/cmTC_0d034.dir/ffmpeg_test.cpp.o -o cmTC_0d034
  -L/root/ffmpeg_build/lib -rdynamic -lavformat -lm -lz -lavcodec -lvpx
  -lpthread -lfdk-aac -lmp3lame -lopus -ltheoraenc -ltheoradec -logg -lvorbis
  -lvorbisenc -lx264 -ldl -lx265 -lstdc++ -lrt -lnuma -lva -lswresample
  -lswscale -lavutil -lva-drm -lva-x11 -lX11 -lvdpau -lavresample-ffmpeg
  -Wl,-rpath,/root/ffmpeg_build/lib

  /root/ffmpeg_build/lib/libavcodec.a(tiff.o): In function
  `tiff_uncompress_lzma':

  /root/ffmpeg_sources/FFmpeg/libavcodec/tiff.c:398: undefined reference to
  `lzma_stream_decoder'

  /root/ffmpeg_sources/FFmpeg/libavcodec/tiff.c:403: undefined reference to
  `lzma_code'

  /root/ffmpeg_sources/FFmpeg/libavcodec/tiff.c:404: undefined reference to
  `lzma_end'

  collect2: error: ld returned 1 exit status

  CMakeFiles/cmTC_0d034.dir/build.make:97: recipe for target 'cmTC_0d034'
  failed

  make[1]: *** [cmTC_0d034] Error 1

  make[1]: Leaving directory '/hello/opencv-3.4.1/build/CMakeFiles/CMakeTmp'

  Makefile:126: recipe for target 'cmTC_0d034/fast' failed

  make: *** [cmTC_0d034/fast] Error 2

Call Stack (most recent call first):
  CMakeLists.txt:636 (include)

Seems like -llzma is missing in cmake's point of view of ${FFMPEG_LIBRARIES} .

@Brainiarc7

This comment has been minimized.

Show comment
Hide comment
@Brainiarc7

Brainiarc7 Jun 2, 2018

Hmm, @minostauros,

It's been a while since I built FFmpeg with OpenCV.

I'll recheck and retest.

Owner

Brainiarc7 commented Jun 2, 2018

Hmm, @minostauros,

It's been a while since I built FFmpeg with OpenCV.

I'll recheck and retest.

@Brainiarc7

This comment has been minimized.

Show comment
Hide comment
@Brainiarc7

Brainiarc7 Jun 4, 2018

Notes: Updated for Ubuntu 18.04LTS.

Changes: The nvidia-cuda-toolkit available in the standard Ubuntu repositories is sufficient.
Should that change, this document will be updated to reflect that.

Update: Reverted. Still investigating.

Owner

Brainiarc7 commented Jun 4, 2018

Notes: Updated for Ubuntu 18.04LTS.

Changes: The nvidia-cuda-toolkit available in the standard Ubuntu repositories is sufficient.
Should that change, this document will be updated to reflect that.

Update: Reverted. Still investigating.

@Brainiarc7

This comment has been minimized.

Show comment
Hide comment
@Brainiarc7

Brainiarc7 Jun 27, 2018

Notes added on fixing broken nvidia driver installation for Ubuntu 18.04LTS.
The kernel sources are needed by the DKMS autoinstaller.

Now adding build instructions for libaom enablement.

Owner

Brainiarc7 commented Jun 27, 2018

Notes added on fixing broken nvidia driver installation for Ubuntu 18.04LTS.
The kernel sources are needed by the DKMS autoinstaller.

Now adding build instructions for libaom enablement.

@ph3n0

This comment has been minimized.

Show comment
Hide comment
@ph3n0

ph3n0 Aug 20, 2018

I had to add "--extra-libs=-lpthread" to the FFmpeg configure do to the x265 issues, but other than that it worked like a charm, thanks!

ph3n0 commented Aug 20, 2018

I had to add "--extra-libs=-lpthread" to the FFmpeg configure do to the x265 issues, but other than that it worked like a charm, thanks!

@Brainiarc7

This comment has been minimized.

Show comment
Hide comment
@Brainiarc7

Brainiarc7 Sep 1, 2018

Hello @minostauros,

Can you point to the documentation (of the build steps) you used to deploy OpenCV + FFmpeg? That way I may be able to see what went wrong with your build.

Owner

Brainiarc7 commented Sep 1, 2018

Hello @minostauros,

Can you point to the documentation (of the build steps) you used to deploy OpenCV + FFmpeg? That way I may be able to see what went wrong with your build.

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