Last active
December 6, 2017 10:45
-
-
Save trappedinspacetime/d1375e2965af5021843e0fed0e27f8a5 to your computer and use it in GitHub Desktop.
ffmpeg compile on Ubuntu based on https://raw.githubusercontent.com/markus-perl/ffmpeg-build-script/master/build-ffmpeg
This file contains 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 | |
# https://github.com/markus-perl/ffmpeg-build-script | |
VERSION=0.8 | |
CWD=$(pwd) | |
PACKAGES="$CWD/packages" | |
WORKSPACE="$CWD/workspace" | |
CC=clang | |
LDFLAGS="-L${WORKSPACE}/lib -lm" | |
CFLAGS="-I${WORKSPACE}/include" | |
PKG_CONFIG_PATH="${WORKSPACE}/lib/pkgconfig" | |
LD_LIBRARY_PATH="${WORKSPACE}/lib" | |
# Speed up the process | |
# Env Var NUMJOBS overrides automatic detection | |
if [[ -n $NUMJOBS ]]; then | |
MJOBS=$NUMJOBS | |
elif [[ -f /proc/cpuinfo ]]; then | |
MJOBS=$(grep -c processor /proc/cpuinfo) | |
elif [[ "$OSTYPE" == "darwin"* ]]; then | |
MJOBS=$(sysctl -n machdep.cpu.thread_count) | |
else | |
MJOBS=4 | |
fi | |
make_dir () { | |
if [ ! -d $1 ]; then | |
if ! mkdir $1; then | |
printf "\n Failed to create dir %s" "$1"; | |
exit 1 | |
fi | |
fi | |
} | |
remove_dir () { | |
if [ -d $1 ]; then | |
rm -r "$1" | |
fi | |
} | |
download () { | |
if [ ! -f "$PACKAGES/$2" ]; then | |
echo "Downloading $1" | |
curl -L --silent -o "$PACKAGES/$2" "$1" | |
EXITCODE=$? | |
if [ $EXITCODE -ne 0 ]; then | |
echo "" | |
echo "Failed to download $1. Exitcode $EXITCODE. Retrying in 10 seconds"; | |
sleep 10 | |
curl -L --silent -o "$PACKAGES/$2" "$1" | |
fi | |
EXITCODE=$? | |
if [ $EXITCODE -ne 0 ]; then | |
echo "" | |
echo "Failed to download $1. Exitcode $EXITCODE"; | |
exit 1 | |
fi | |
echo "... Done" | |
if ! tar -xvf "$PACKAGES/$2" -C "$PACKAGES" 2>/dev/null >/dev/null && ! unzip "$PACKAGES/$2" -d "$PACKAGES" 2>/dev/null >/dev/null ; then | |
echo "Failed to extract $2"; | |
exit 1 | |
fi | |
fi | |
} | |
execute () { | |
echo "$ $*" | |
if [[ ! $VERBOSE == "yes" ]]; then | |
OUTPUT="$($@ 2>&1)" | |
else | |
$@ | |
fi | |
if [ $? -ne 0 ]; then | |
echo "$OUTPUT" | |
echo "" | |
echo "Failed to Execute $*" >&2 | |
exit 1 | |
fi | |
} | |
build () { | |
echo "" | |
echo "building $1" | |
echo "=======================" | |
if [ -f "$PACKAGES/$1.done" ]; then | |
echo "$1 already built. Remove $PACKAGES/$1.done lockfile to rebuild it." | |
return 1 | |
fi | |
return 0 | |
} | |
command_exists() { | |
if ! [[ -x $(command -v "$1") ]]; then | |
return 1 | |
fi | |
return 0 | |
} | |
build_done () { | |
touch "$PACKAGES/$1.done" | |
} | |
echo "ffmpeg-build-script v$VERSION" | |
echo "=========================" | |
echo "" | |
case "$1" in | |
"--cleanup") | |
remove_dir $PACKAGES | |
remove_dir $WORKSPACE | |
echo "Cleanup done." | |
echo "" | |
exit 0 | |
;; | |
"--build") | |
;; | |
*) | |
echo "Usage: $0" | |
echo " --build: start building process" | |
echo " --cleanup: remove all working dirs" | |
echo " --help: show this help" | |
echo "" | |
exit 0 | |
;; | |
esac | |
echo "Using $MJOBS make jobs simultaneously." | |
make_dir $PACKAGES | |
make_dir $WORKSPACE | |
make_dir $CMPL | |
export PATH=${WORKSPACE}/bin:$PATH | |
if ! command_exists "make"; then | |
echo "make not installed."; | |
exit 1 | |
fi | |
if ! command_exists "g++"; then | |
echo "g++ not installed."; | |
exit 1 | |
fi | |
if ! command_exists "curl"; then | |
echo "curl not installed."; | |
exit 1 | |
fi | |
if build "yasm"; then | |
download "http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz" "yasm-1.3.0.tar.gz" | |
cd $PACKAGES/yasm-1.3.0 || exit | |
execute ./configure --prefix=${WORKSPACE} | |
execute make -j $MJOBS | |
execute make install | |
build_done "yasm" | |
fi | |
if build "opencore"; then | |
download "http://downloads.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.5.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fopencore-amr%2Ffiles%2Fopencore-amr%2F&ts=1442256558&use_mirror=netassist" "opencore-amr-0.1.5.tar.gz" | |
cd $PACKAGES/opencore-amr-0.1.5 || exit | |
execute ./configure --prefix=${WORKSPACE} --enable-shared | |
execute make -j $MJOBS | |
execute make install | |
build_done "opencore" | |
fi | |
if build "libvpx"; then | |
download "https://github.com/webmproject/libvpx/archive/v1.5.0.tar.gz" "libvpx-1.5.0.tar.gz" | |
cd $PACKAGES/libvpx* || exit | |
sed -e 's/cp -p/cp/' -i build/make/Makefile | |
execute ./configure --prefix=${WORKSPACE} --disable-unit-tests --enable-shared | |
execute make -j $MJOBS | |
execute make install | |
build_done "libvpx" | |
fi | |
if build "lame"; then | |
download "http://kent.dl.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz" "lame-3.100.tar.gz" | |
cd $PACKAGES/lame-3.100 || exit | |
execute ./configure --prefix=${WORKSPACE} --enable-shared --enable-nasm | |
execute make -j $MJOBS | |
execute make install | |
build_done "lame" | |
fi | |
if build "xvidcore"; then | |
download "http://downloads.xvid.org/downloads/xvidcore-1.3.4.tar.gz" "xvidcore-1.3.4.tar.gz" | |
cd $PACKAGES/xvidcore || exit | |
cd build/generic || exit | |
execute ./configure --prefix=${WORKSPACE} --enable-shared | |
execute make -j $MJOBS | |
execute make install | |
if [[ -f ${WORKSPACE}/lib/libxvidcore.4.dylib ]]; then | |
execute rm "${WORKSPACE}/lib/libxvidcore.4.dylib" | |
fi | |
build_done "xvidcore" | |
fi | |
if build "x264"; then | |
download "ftp://ftp.videolan.org/pub/x264/snapshots/x264-snapshot-20170328-2245.tar.bz2" "last_x264.tar.bz2" | |
cd $PACKAGES/x264-snapshot-* || exit | |
execute ./configure --prefix=${WORKSPACE} --enable-shared | |
execute make -j $MJOBS | |
execute make install | |
# execute make install-lib-static | |
build_done "x264" | |
fi | |
if build "libogg"; then | |
download "http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz" "libogg-1.3.2.tar.gz" | |
cd $PACKAGES/libogg-1.3.2 || exit | |
execute ./configure --prefix=${WORKSPACE} --enable-shared | |
execute make -j $MJOBS | |
execute make install | |
build_done "libogg" | |
fi | |
if build "libvorbis"; then | |
download "http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.5.tar.gz" "libvorbis-1.3.5.tar.gz" | |
cd $PACKAGES/libvorbis-1.3.5 || exit | |
execute ./configure --prefix=${WORKSPACE} --with-ogg-libraries=${WORKSPACE}/lib --with-ogg-includes=${WORKSPACE}/include/ --enable-shared --disable-oggtest | |
execute make -j $MJOBS | |
execute make install | |
build_done "libvorbis" | |
fi | |
if build "libtheora"; then | |
download "https://github.com/xiph/theora/archive/master.zip" "libtheora-master.zip" | |
cd $PACKAGES/theora-master || exit | |
execute ./autogen.sh | |
execute ./configure --prefix=${WORKSPACE} --with-ogg-libraries=${WORKSPACE}/lib --with-ogg-includes=${WORKSPACE}/include/ --with-vorbis-libraries=${WORKSPACE}/lib --with-vorbis-includes=${WORKSPACE}/include/ --enable-shared --disable-oggtest --disable-vorbistest --disable-examples --disable-asm --disable-doc | |
execute make -j $MJOBS | |
execute make install | |
build_done "libtheora" | |
fi | |
if build "pkg-config"; then | |
download "http://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz" "pkg-config-0.29.2.tar.gz" | |
cd $PACKAGES/pkg-config-0.29.2 || exit | |
execute ./configure --silent --prefix=${WORKSPACE} --with-pc-path=${WORKSPACE}/lib/pkgconfig --with-internal-glib | |
execute make -j $MJOBS | |
execute make install | |
build_done "pkg-config" | |
fi | |
if build "cmake"; then | |
download "https://cmake.org/files/v3.10/cmake-3.10.0.tar.gz" "cmake-3.10.0.tar.gz" | |
cd $PACKAGES/cmake-3.10.0 || exit | |
rm Modules/FindJava.cmake | |
perl -p -i -e "s/get_filename_component.JNIPATH/#get_filename_component(JNIPATH/g" Tests/CMakeLists.txt | |
perl -p -i -e "s/get_filename_component.JNIPATH/#get_filename_component(JNIPATH/g" Tests/CMakeLists.txt | |
execute ./configure --prefix=${WORKSPACE} | |
execute make -j $MJOBS | |
execute make install | |
build_done "cmake" | |
fi | |
if build "vid_stab"; then | |
download "https://github.com/georgmartius/vid.stab/archive/master.zip" "vid.stab-master.zip" | |
cd $PACKAGES/vid.stab-master || exit | |
# perl -p -i -e "s/vidstab SHARED/vidstab STATIC/" CMakeLists.txt | |
execute cmake -DCMAKE_INSTALL_PREFIX:PATH=${WORKSPACE} . | |
execute make install | |
build_done "vid_stab" | |
fi | |
if build "x265"; then | |
download "https://bitbucket.org/multicoreware/x265/downloads/x265_2.6.tar.gz" "x265_2.6.tar.gz" | |
cd $PACKAGES/x265_v2.6 || exit | |
cd source || exit | |
execute cmake -DCMAKE_INSTALL_PREFIX:PATH=${WORKSPACE} -DENABLE_SHARED:bool=on . | |
execute make -j $MJOBS | |
execute make install | |
sed "s/-lx265/-lx265 -lstdc++/g" "$WORKSPACE/lib/pkgconfig/x265.pc" > "$WORKSPACE/lib/pkgconfig/x265.pc.tmp" | |
mv "$WORKSPACE/lib/pkgconfig/x265.pc.tmp" "$WORKSPACE/lib/pkgconfig/x265.pc" | |
build_done "x265" | |
fi | |
if build "fdk_aac"; then | |
download "http://downloads.sourceforge.net/project/opencore-amr/fdk-aac/fdk-aac-0.1.5.tar.gz?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fopencore-amr%2Ffiles%2Ffdk-aac%2F&ts=1457561564&use_mirror=kent" "fdk-aac-0.1.5.tar.gz" | |
cd $PACKAGES/fdk-aac* || exit | |
execute ./configure --prefix=${WORKSPACE} --enable-shared | |
execute make -j $MJOBS | |
execute make install | |
build_done "fdk_aac" | |
fi | |
build "ffmpeg" | |
download "https://github.com/FFmpeg/FFmpeg/archive/release/3.4.zip" "ffmpeg-3.4.zip" | |
cd $PACKAGES/FFmpeg-release-3.4 || exit | |
CFLAGS="-I$WORKSPACE/include" LDFLAGS="-L$WORKSPACE/lib" | |
execute ./configure --prefix=${WORKSPACE} --extra-cflags="-I$WORKSPACE/include" --extra-ldflags="-L$WORKSPACE/lib" \ | |
--enable-shared \ | |
--disable-debug \ | |
--disable-doc \ | |
--enable-gpl \ | |
--enable-version3 \ | |
--enable-nonfree \ | |
--enable-pthreads \ | |
--enable-libvpx \ | |
--enable-libmp3lame \ | |
--enable-libtheora \ | |
--enable-libvorbis \ | |
--enable-libx264 \ | |
--enable-libx265 \ | |
--enable-runtime-cpudetect \ | |
--enable-libfdk-aac \ | |
--enable-avfilter \ | |
--enable-libopencore_amrwb \ | |
--enable-libopencore_amrnb \ | |
--enable-filters \ | |
--enable-libvidstab | |
# enable all filters | |
# enable AAC de/encoding via libfdk-aac [no] | |
# enable detecting cpu capabilities at runtime (smaller binary) | |
# enable HEVC encoding via x265 [no] | |
# enable H.264 encoding via x264 [no] | |
# enable Vorbis en/decoding via libvorbis, native implementation exists [no] | |
# enable Theora encoding via libtheora [no] | |
# enable MP3 encoding via libmp3lame [no] | |
# enable VP8 and VP9 de/encoding via libvpx [no] | |
# enable pthreads [autodetect] | |
# allow use of nonfree code, the resulting libs and binaries will be unredistributable [no] | |
# upgrade (L)GPL to version 3 [no] | |
# allow use of GPL code, the resulting libs and binaries will be under GPL [no] | |
# do not build documentation | |
# disable ffserver build | |
# disable ffplay build | |
# build static libraries [no] | |
# disable debugging symbols | |
# disable build shared libraries [no] | |
execute make -j $MJOBS | |
execute make install | |
INSTALL_FOLDER="/usr/local/bin" | |
if [[ "$OSTYPE" == "darwin"* ]]; then | |
INSTALL_FOLDER="/usr/local/bin" | |
fi | |
echo "" | |
echo "Building done. The binary can be found here: $WORKSPACE/bin/ffmpeg" | |
echo "" | |
if [[ ! $SKIPINSTALL == "yes" ]]; then | |
if command_exists "sudo"; then | |
read -r -p "Install the binary to your $INSTALL_FOLDER folder? [Y/n] " response | |
case $response in | |
[yY][eE][sS]|[yY]) | |
sudo cp "$WORKSPACE/bin/ffmpeg" "$INSTALL_FOLDER/ffmpeg" | |
sudo cp "$WORKSPACE/bin/ffprobe" "$INSTALL_FOLDER/ffprobe" | |
echo "Done. ffmpeg is now installed to your system" | |
;; | |
esac | |
fi | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment