Skip to content

Instantly share code, notes, and snippets.

@rainabba
Last active November 13, 2022 05:09
Show Gist options
  • Save rainabba/07425c3bc14a0bb51632f12e913d9081 to your computer and use it in GitHub Desktop.
Save rainabba/07425c3bc14a0bb51632f12e913d9081 to your computer and use it in GitHub Desktop.
Building ffmpeg on AWS Linux AMI (G2 instance)

First, I should be clear that this was done on a G2 AWS instance and I started with working nvidia support by following http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using_cluster_computing.html

From that (or if you're feeling more bold), the thing to take is getting the right binary install package and running it. Look at http://www.nvidia.com/object/unix.html and get the package you want (at the time, I'm using 'Latest Long Lived Branch version: 361.45.11'), then run the file you get. For example, sudo sh ./NVIDIA-Linux-x86_64-361.45.11.run.

I do not have time to test on a clean instance so you may need a bit more setup that I've not mentioned and I make no guarantees anyway since I hardly know what I'm doing here :)

The ffmpeg_build.sh script was mostly copy/paste from the guide at https://trac.ffmpeg.org/wiki/CompilationGuide/Centos and with significant help from folks on FreeNode #ffmpeg (notably furq and JEEB though there were others).

The steps for adding OpenCL headers support was borrowed from https://wiki.tiker.net/OpenCLHowTo#Installing_the_Nvidia_ICD

The OpenCL version I used was found by looking at https://www.khronos.org/registry/cl/, then finding the root url for the appropriate opencl.h link

To help me know which libraries I should be building (steps prior to actually building ffmpeg), I needed to know what was build-in (for endcoding in particular) and that can be found at: https://ffmpeg.org/general.html#Supported-File-Formats_002c-Codecs-or-Features

#!/bin/sh
#stop script on any errors / non-0 code returns
set -e
#prepare/cleanup environment
cd ~
rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffserver,lame,vsyasm,x264,yasm,ytasm}
mkdir ~/ffmpeg_sources
#place opencl headers
TGT_DIR=$HOME/ffmpeg_build/include/CL && mkdir -p $TGT_DIR && cd $TGT_DIR && wget https://raw.githubusercontent.com/KhronosGroup/OpenCL-Headers/opencl21/{opencl,cl_platform,cl,cl_ext,cl_gl,cl_gl_ext}.h
#compile yasm (needed by dependencies)
cd ~/ffmpeg_sources
git clone --depth 1 git://github.com/yasm/yasm.git
cd yasm
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build"
make -j 32
touch ./.yasm
make install
make distclean
#compile x264
cd ~/ffmpeg_sources
git clone --depth 1 git://git.videolan.org/x264
cd x264
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --enable-static
make -j 32
make install
make distclean
#compile x265
cd ~/ffmpeg_sources
hg clone https://bitbucket.org/multicoreware/x265
cd ~/ffmpeg_sources/x265/build/linux
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source
make -j 32
make install
#compile fdk-aac for AAC support
cd ~/ffmpeg_sources
git clone --depth 1 git://git.code.sf.net/p/opencore-amr/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make -j 32
make install
make distclean
#compile libvpx for VP8/VP9 support
cd ~/ffmpeg_sources
git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git
cd libvpx
./configure --prefix="$HOME/ffmpeg_build" --disable-examples
make -j 32
make install
make clean
#compile the ffmpeg binaries
cd ~/ffmpeg_sources
git clone http://source.ffmpeg.org/git/ffmpeg.git
cd ffmpeg
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libfreetype --enable-libx264 --enable-libx265 --enable-opencl
make -j 32
make install
make distclean
hash -r
cd $HOME/ffmpeg_build/bin
echo "Now you should see your executables if all went well"
ls -lah
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment