Skip to content

Instantly share code, notes, and snippets.

@Ayke
Last active March 13, 2020 00:10
Show Gist options
  • Save Ayke/f2e7a54c61d47a09ba9df2b9b2737316 to your computer and use it in GitHub Desktop.
Save Ayke/f2e7a54c61d47a09ba9df2b9b2737316 to your computer and use it in GitHub Desktop.
ffmpeg installation from source (full installation without libaom)

Installation

Environment: Ubuntu 16.04

Package requirement for ffmpeg

sudo apt-get update -qq && sudo apt-get -y install \
  autoconf \
  automake \
  build-essential \
  cmake \
  git-core \
  libass-dev \
  libfreetype6-dev \
  libsdl2-dev \
  libtool \
  libva-dev \
  libvdpau-dev \
  libvorbis-dev \
  libxcb1-dev \
  libxcb-shm0-dev \
  libxcb-xfixes0-dev \
  pkg-config \
  texinfo \
  wget \
  zlib1g-dev

Create bin folder at ~/bin for ffmpeg, install third-party libraries (except libaom)

mkdir -p ~/ffmpeg_sources ~/bin

sudo apt-get -y install nasm \
  yasm \
  libx264-dev \
  libx265-dev libnuma-dev \
  libvpx-dev \
  libfdk-aac-dev \
  libmp3lame-dev \
  libopus-dev 

Install CUDA Decoder/Encoder: (See https://developer.nvidia.com/ffmpeg)

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

Install all third-party libraries (except libaom) with GPU support

cd ~/ffmpeg_sources && \
wget -O ffmpeg-snapshot.tar.bz2 https://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 && \
tar xjvf ffmpeg-snapshot.tar.bz2 && \
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" \
  --extra-libs="-lpthread -lm" \
  --bindir="$HOME/bin" \
  --enable-gpl \
  --enable-libass \
  --enable-libfdk-aac \
  --enable-libfreetype \
  --enable-libmp3lame \
  --enable-libopus \
  --enable-libvorbis \
  --enable-libvpx \
  --enable-libx264 \
  --enable-libx265 \
  --enable-nonfree \
  --extra-cflags=-I/usr/local/cuda/include \
  --extra-ldflags=-L/usr/local/cuda/lib64 \
  --enable-libnpp \
  --enable-cuda \
  --enable-cuvid \
  --enable-nvenc && \
PATH="$HOME/bin:$PATH" make -j7 && \
make install && \
hash -r

This gist will install FFMpeg to ~/bin (/home/username/bin), if you want to install for all users, after the installation, just move the file to /usr/local/bin (remember to chmod)

Uninstall

rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffplay,x264,x265,nasm,vsyasm,yasm,ytasm}
sed -i '/ffmpeg_build/d' ~/.manpath
hash -r

If you have moved the file to new location (such as /usr/local/bin, change the location correspondingly)

Problems

ERROR: cuda requested, but not all dependencies are satisfied: ffnvcodec

Make sure you have installed nv-codec-headers (see above section)

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