Created
April 26, 2015 22:41
-
-
Save clchiou/9f4490da1293aaa2b4b2 to your computer and use it in GitHub Desktop.
Build script for ffmpeg and its dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script checks out ffmpeg and its dependencies and builds them. | |
# | |
# Please refer to | |
# https://trac.ffmpeg.org/wiki/CompilationGuide | |
# for more information. | |
# | |
set -o errexit -o pipefail -o nounset | |
do_checkout() { | |
echo "### checkout repos" | |
cd "${ROOT}" | |
# yasm is needed by x264. | |
clone_git git://github.com/yasm/yasm.git | |
clone_git git://git.videolan.org/x264.git | |
if [ -d "x265" ]; then | |
echo "### skip x265" | |
else | |
hg clone https://bitbucket.org/multicoreware/x265 | |
fi | |
clone_git git://github.com/mstorsjo/fdk-aac | |
if [ -f "lame-3.99.5.tar.gz" ]; then | |
echo "### skip lame" | |
else | |
wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz | |
fi | |
clone_git git://git.opus-codec.org/opus.git | |
clone_git https://chromium.googlesource.com/webm/libvpx | |
clone_git git://source.ffmpeg.org/ffmpeg.git | |
} | |
do_build() { | |
local build="${ROOT}/build" | |
local bin="${ROOT}/build/bin" | |
local path="${bin}:${PATH}" | |
echo "### build repos" | |
mkdir -p "${build}" | |
mkdir -p "${bin}" | |
if [ -f "${build}/yasm" ]; then | |
echo "### skip yasm" | |
else | |
echo "### yasm" | |
cd "${ROOT}/yasm" | |
check_clean_git_tree | |
#git checkout v1.3.0 | |
./autogen.sh | |
./configure --prefix="${build}" --bindir="${bin}" | |
make | |
make install | |
#make distclean | |
rm -f config.h.in config/test-driver # XXX Hack for a git-clean tree. | |
touch "${build}/yasm" | |
fi | |
if [ -f "${build}/x264" ]; then | |
echo "### skip x264" | |
else | |
echo "### x264" | |
cd "${ROOT}/x264" | |
check_clean_git_tree | |
PATH="${path}" ./configure \ | |
--prefix="${build}" --bindir="${bin}" --enable-static | |
PATH="${path}" make | |
make install | |
#make distclean | |
touch "${build}/x264" | |
fi | |
if [ -f "${build}/x265" ]; then | |
echo "### skip x265" | |
else | |
echo "### x265" | |
cd "${ROOT}/x265" | |
check_clean_hg_tree | |
cd build/linux | |
PATH="${path}" cmake \ | |
-G "Unix Makefiles" \ | |
-DCMAKE_INSTALL_PREFIX="${build}" \ | |
-DENABLE_SHARED:bool=off \ | |
../../source | |
make | |
make install | |
#make clean | |
touch "${build}/x265" | |
fi | |
if [ -f "${build}/fdk-aac" ]; then | |
echo "### skip fdk-aac" | |
else | |
echo "### fdk-aac" | |
cd "${ROOT}/fdk-aac" | |
check_clean_git_tree | |
./autogen.sh | |
./configure --prefix="${build}" --disable-shared | |
make | |
make install | |
#make distclean | |
touch "${build}/fdk-aac" | |
fi | |
if [ -f "${build}/lame" ]; then | |
echo "### skip lame" | |
else | |
echo "### lame" | |
cd "${ROOT}" | |
rm -rf lame-3.99.5 | |
tar xzvf lame-3.99.5.tar.gz | |
cd lame-3.99.5 | |
./configure --prefix="${build}" --enable-nasm --disable-shared | |
make | |
make install | |
#make distclean | |
touch "${build}/lame" | |
fi | |
if [ -f "${build}/opus" ]; then | |
echo "### skip opus" | |
else | |
echo "### opus" | |
cd "${ROOT}/opus" | |
check_clean_git_tree | |
#git checkout v1.1 | |
./autogen.sh | |
./configure --prefix="${build}" --disable-shared | |
make | |
make install | |
#make distclean | |
rm -f "test-driver" # XXX Hack for a git-clean tree. | |
touch "${build}/opus" | |
fi | |
if [ -f "${build}/libvpx" ]; then | |
echo "### skip libvpx" | |
else | |
echo "### libvpx" | |
cd "${ROOT}/libvpx" | |
check_clean_git_tree | |
#git checkout v1.3.0 | |
PATH="${path}" ./configure \ | |
--prefix="${build}" --disable-examples --disable-unit-tests | |
PATH="${path}" make | |
make install | |
#make clean | |
touch "${build}/libvpx" | |
fi | |
if [ -f "${build}/ffmpeg" ]; then | |
echo "### skip ffmpeg" | |
else | |
echo "### ffmpeg" | |
cd "${ROOT}/ffmpeg" | |
check_clean_git_tree | |
PATH="${path}" PKG_CONFIG_PATH="${build}/lib/pkgconfig" ./configure \ | |
--prefix="${build}" \ | |
--pkg-config-flags="--static" \ | |
--extra-cflags="-I${build}/include" \ | |
--extra-ldflags="-L${build}/lib" \ | |
--bindir="${bin}" \ | |
--enable-gpl \ | |
--enable-libass \ | |
--enable-libfdk-aac \ | |
--enable-libfreetype \ | |
--enable-libmp3lame \ | |
--enable-libopus \ | |
--enable-libtheora \ | |
--enable-libvorbis \ | |
--enable-libvpx \ | |
--enable-libx264 \ | |
--enable-libx265 \ | |
--enable-nonfree | |
PATH="${path}" make | |
make install | |
#make distclean | |
hash -r | |
touch "${build}/ffmpeg" | |
fi | |
} | |
clone_git() { | |
local repo="${1}" | |
local dir="${2:-$(basename "${repo%.git}")}" | |
if [ -d "${dir}" ]; then | |
echo "### skip ${dir}" | |
else | |
git clone "${repo}" "${dir}" | |
fi | |
} | |
check_clean_git_tree() { | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "$(pwd) is not clean" | |
exit 1 | |
fi | |
} | |
check_clean_hg_tree() { | |
if [ -n "$(hg status)" ]; then | |
echo "$(pwd) is not clean" | |
exit 1 | |
fi | |
} | |
abspath() { | |
local curdir="$(pwd)" | |
cd "${1}" | |
pwd | |
cd "${curdir}" | |
} | |
usage() { | |
echo "Usage: ${PROG} {checkout|build} ROOT" | |
} | |
# main | |
PROG="$(basename "${0}")" | |
if [ -z "${1:-}" -o -z "${2:-}" ]; then | |
usage | |
exit 1 | |
fi | |
ROOT="$(abspath "${2}")" | |
case "${1}" in | |
checkout) | |
do_checkout | |
;; | |
build) | |
do_checkout | |
do_build | |
;; | |
*) | |
echo "Unknown: ${1}" | |
usage | |
exit 1 | |
;; | |
esac | |
echo "### complete" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment