Skip to content

Instantly share code, notes, and snippets.

@rudolfbyker
Created December 30, 2017 16:41
Show Gist options
  • Save rudolfbyker/e3812b981765eb7271d9902f29b301c8 to your computer and use it in GitHub Desktop.
Save rudolfbyker/e3812b981765eb7271d9902f29b301c8 to your computer and use it in GitHub Desktop.
Compile and install the latest FFMPEG
#!/usr/bin/env bash
# FFMPEG installation script by RW Byker, based on the guide at https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
DATE=$(date "+%Y%m%d_%H%M%S")
DIR_SOURCES="$HOME/installers/ffmpeg_sources"
DIR_BUILD="$HOME/installers/ffmpeg_build"
DIR_BIN="$HOME/bin"
DIR_OLDVERSION="$HOME/installers/ffmpeg_old_${DATE}"
DIR_LOG="$HOME/installers/ffmpeg_build_logs_${DATE}"
FFMPEG_FLAGS=""
# Don't continue if there is an error.
set -e
# Show all commands as they run
set -x
# Move previous versions out of the way
mkdir -p ${DIR_OLDVERSION}
mv ${DIR_SOURCES} -t ${DIR_OLDVERSION} || :
mv ${DIR_BUILD} -t ${DIR_OLDVERSION} || :
mv ${DIR_BIN}/{ffmpeg,ffprobe,ffplay,ffserver,x264,x265} -t ${DIR_OLDVERSION} || :
# Create directories for sources and building
mkdir -p ${DIR_SOURCES}
mkdir -p ${DIR_BUILD}
mkdir -p ${DIR_BIN}
mkdir -p ${DIR_LOG}
# Update or install dependencies
sudo apt update > ${DIR_LOG}/apt.update.log
sudo apt install autoconf \
automake \
build-essential \
cmake \
git \
libass-dev \
libfreetype6-dev \
libsdl2-dev \
libtheora-dev \
libtool \
libva-dev \
libvdpau-dev \
libvorbis-dev \
libxcb1-dev \
libxcb-shm0-dev \
libxcb-xfixes0-dev \
mercurial \
pkg-config \
texinfo \
wget \
zlib1g-dev > ${DIR_LOG}/apt.dependencies.log
# Use 4 threads for compilation
export MAKEFLAGS="-j4"
# NASM
cd ${DIR_SOURCES}
wget http://www.nasm.us/pub/nasm/releasebuilds/2.13.02/nasm-2.13.02.tar.bz2
tar xjf nasm-2.13.02.tar.bz2
cd nasm-2.13.02
./autogen.sh 1> ${DIR_LOG}/nasm.autogen.log 2> ${DIR_LOG}/nasm.autogen.err
PATH="${DIR_BIN}:$PATH" ./configure --prefix="${DIR_BUILD}" --bindir="${DIR_BIN}" 1> ${DIR_LOG}/nasm.configure.log 2> ${DIR_LOG}/nasm.configure.err
make 1> ${DIR_LOG}/nasm.make.log 2> ${DIR_LOG}/nasm.make.err
make install 1> ${DIR_LOG}/nasm.install.log 2> ${DIR_LOG}/nasm.install.err
# YASM >= 1.2.0
sudo apt install yasm > ${DIR_LOG}/yasm.install.log
# libx264 >= 118
FFMPEG_FLAGS="--enable-gpl --enable-libx264 ${FFMPEG_FLAGS}"
sudo apt install libx264-dev > ${DIR_LOG}/lib264dev.install.log
# libx265 >= 68
FFMPEG_FLAGS="--enable-libx265 ${FFMPEG_FLAGS}"
# Can't use apt for this one, as it has to be statically compiled
cd ${DIR_SOURCES}
if cd x265 2> /dev/null; then hg pull && hg update; else hg clone https://bitbucket.org/multicoreware/x265; fi
cd x265/build/linux
PATH="${DIR_BIN}:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="${DIR_BUILD}" -DENABLE_SHARED:bool=off ../../source 1> ${DIR_LOG}/lib265.cmake.log 2> ${DIR_LOG}/lib265.cmake.err
PATH="${DIR_BIN}:$PATH" make 1> ${DIR_LOG}/lib265.make.log 2> ${DIR_LOG}/lib265.make.err
make install 1> ${DIR_LOG}/lib265.install.log 2> ${DIR_LOG}/lib265.install.err
# libvpx >= 0.9.7
FFMPEG_FLAGS="--enable-libvpx ${FFMPEG_FLAGS}"
sudo apt install libvpx-dev > ${DIR_LOG}/libvpx.install.log
# libfdk-aac
FFMPEG_FLAGS="--enable-libfdk-aac --enable-nonfree ${FFMPEG_FLAGS}"
sudo apt install libfdk-aac-dev > ${DIR_LOG}/libfdkaacdev.install.log
# libmp3lame >= 3.98.3
FFMPEG_FLAGS="--enable-libmp3lame ${FFMPEG_FLAGS}"
sudo apt install libmp3lame-dev > ${DIR_LOG}/libmp3lamedev.install.log
# libopus >= 1.1
FFMPEG_FLAGS="--enable-libopus ${FFMPEG_FLAGS}"
sudo apt install libopus-dev > ${DIR_LOG}/libopusdev.install.log
# ffmpeg
FFMPEG_FLAGS="--enable-libass --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libpulse ${FFMPEG_FLAGS}"
cd ${DIR_SOURCES}
wget -O ffmpeg-snapshot.tar.bz2 http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xjf ffmpeg-snapshot.tar.bz2
cd ffmpeg
PATH="${DIR_BIN}:$PATH" PKG_CONFIG_PATH="${DIR_BUILD}/lib/pkgconfig" ./configure \
--prefix="${DIR_BUILD}" \
--pkg-config-flags="--static" \
--extra-cflags="-I${DIR_BUILD}/include" \
--extra-ldflags="-L${DIR_BUILD}/lib" \
--extra-libs="-lpthread -lm" \
--bindir="${DIR_BIN}" \
${FFMPEG_FLAGS} 1> ${DIR_LOG}/ffmpeg.configure.log 2> ${DIR_LOG}/ffmpeg.configure.err
PATH="${DIR_BIN}:$PATH" make 1> ${DIR_LOG}/ffmpeg.make.log 2> ${DIR_LOG}/ffmpeg.make.err
make install 1> ${DIR_LOG}/ffmpeg.install.log 2> ${DIR_LOG}/ffmpeg.install.err
hash -r
echo "DONE!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment