Last active
December 3, 2016 14:44
-
-
Save Mirabis/8ea725220e6cdca73938 to your computer and use it in GitHub Desktop.
Auto-Compile ffmpeg for Linux
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/sh | |
# http://www.github.com/markus-perl (original) | |
# Version 0.2 | |
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" | |
make_dir () { | |
if [ ! -d $1 ]; then | |
if ! mkdir $1; then | |
echo "\nFailed to create dir $1"; | |
exit 1 | |
fi | |
fi | |
} | |
remove_dir () { | |
if [ -d $1 ]; then | |
rm -r "$1" | |
fi | |
} | |
download () { | |
if [ ! -f "$PACKAGES/$2" ]; then | |
printf "Downloading $1" | |
curl -L --silent -o "$PACKAGES/$2" "$1" | |
EXITCODE=$? | |
if [ $EXITCODE -ne 0 ]; then | |
echo "" | |
echo "Failed to download $1. Exitcode $EXITCODE"; | |
exit 1 | |
fi | |
printf " ... Done\n" | |
if ! tar -xvf "$PACKAGES/$2" -C "$PACKAGES" 2>/dev/null >/dev/null; then | |
echo "Failed to extract $2"; | |
exit 1 | |
fi | |
fi | |
} | |
execute () { | |
echo "$ $@" | |
OUTPUT="$($@ 2>&1)" | |
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 | |
} | |
build_done () { | |
touch "$PACKAGES/$1.done" | |
} | |
case "$1" in | |
"--cleanup") | |
remove_dir $PACKAGES | |
remove_dir $WORKSPACE | |
echo "Cleanup done" | |
exit 0 | |
;; | |
"--build") | |
;; | |
*) | |
echo "Usage: $0" | |
echo " --build: start building process" | |
echo " --cleanup: remove all working dirs" | |
echo " --help: show this help" | |
exit 0 | |
;; | |
esac | |
make_dir $PACKAGES | |
make_dir $WORKSPACE | |
make_dir $CMPL | |
export PATH=${WORKSPACE}/bin:$PATH | |
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 | |
execute ./configure --prefix=${WORKSPACE} | |
execute make -j 4 | |
execute make install | |
build_done "yasm" | |
fi | |
if build "opencore"; then | |
download "http://garr.dl.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.3.tar.gz" "opencore-amr-0.1.3.tar.gz" | |
cd $PACKAGES/opencore-amr-0.1.3 | |
execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static | |
execute make -j 4 | |
execute make install | |
build_done "opencore" | |
fi | |
if build "libvpx"; then | |
download "http://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2" "libvpx-v1.3.0.tar.bz2" | |
cd $PACKAGES/libvpx-v1.3.0 | |
execute ./configure --prefix=${WORKSPACE} --disable-unit-tests --disable-shared | |
execute make -j 4 | |
execute make install | |
build_done "libvpx" | |
fi | |
if build "lame"; then | |
download "http://kent.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz" "lame-3.99.5.tar.gz" | |
cd $PACKAGES/lame-3.99.5 | |
execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static | |
execute make -j 4 | |
execute make install | |
build_done "lame" | |
fi | |
if build "xvidcore"; then | |
download "http://downloads.xvid.org/downloads/xvidcore-1.3.3.tar.gz" "xvidcore-1.3.3.tar.gz" | |
cd $PACKAGES/xvidcore | |
cd build/generic | |
execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static | |
execute make -j 4 | |
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/last_x264.tar.bz2" "last_x264.tar.bz2" | |
cd $PACKAGES/x264-snapshot-* | |
execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static | |
execute make -j 4 | |
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 | |
execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static | |
execute make -j 4 | |
execute make install | |
build_done "libogg" | |
fi | |
if build "libvorbis"; then | |
download "http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz" "libvorbis-1.3.4.tar.gz" | |
cd $PACKAGES/libvorbis-1.3.4 | |
execute ./configure --prefix=${WORKSPACE} --with-ogg-libraries=${WORKSPACE}/lib --with-ogg-includes=${WORKSPACE}/include/ --enable-static --disable-shared --disable-oggtest | |
execute make -j 4 | |
execute make install | |
build_done "libvorbis" | |
fi | |
if build "libtheora"; then | |
download "http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz" "libtheora-1.1.1.tar.bz" | |
cd $PACKAGES/libtheora-1.1.1 | |
sed "s/-fforce-addr//g" configure > configure.patched | |
chmod +x configure.patched | |
mv configure.patched configure | |
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-static --disable-shared --disable-oggtest --disable-vorbistest --disable-examples --disable-asm | |
execute make -j 4 | |
execute make install | |
build_done "libtheora" | |
fi | |
if build "pkg-config"; then | |
download "http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz" "pkg-config-0.28.tar.gz" | |
cd $PACKAGES/pkg-config-0.28 | |
execute ./configure --silent --prefix=${WORKSPACE} --with-pc-path=${WORKSPACE}/lib/pkgconfig --with-internal-glib | |
execute make -j 4 | |
execute make install | |
build_done "pkg-config" | |
fi | |
if build "cmake"; then | |
download "http://www.cmake.org/files/v3.0/cmake-3.0.2.tar.gz" "cmake-3.0.2.tar.gz" | |
cd $PACKAGES/cmake* | |
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 4 | |
execute make install | |
build_done "cmake" | |
fi | |
if build "vid_stab"; then | |
download "https://codeload.github.com/georgmartius/vid.stab/legacy.tar.gz/release-0.98b" "vid.stab-0.98b-transcode-1.1-binary-x86_64.tgz" | |
cd $PACKAGES/georgmartius-vid* | |
perl -p -i -e "s/vidstab SHARED/vidstab STATIC/" CMakeLists.txt | |
execute cmake -DCMAKE_INSTALL_PREFIX:PATH=${WORKSPACE} . | |
execute make -s install | |
build_done "vid_stab" | |
fi | |
if build "x265"; then | |
download "https://bitbucket.org/multicoreware/x265/downloads/x265_1.7.tar.gz" "x265-1.7.tar.gz" | |
cd $PACKAGES/x265_1.7 | |
cd source | |
execute cmake -DCMAKE_INSTALL_PREFIX:PATH=${WORKSPACE} -DENABLE_SHARED:bool=off $PACKAGES/x265_1.7/source | |
execute make -j 4 | |
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.3.tar.gz" "fdk-aac-0.1.3.tar.gz" | |
download "http://ftp.cc.uoc.gr/mirrors/linux/lfs/LFS/7.6/f/fdk-aac-0.1.3.tar.gz" "fdk-aac-0.1.3.tar.gz" | |
cd $PACKAGES/fdk-aac* | |
execute ./configure --prefix=${WORKSPACE} --disable-shared --enable-static | |
execute make -j 4 | |
execute make install | |
build_done "fdk_aac" | |
fi | |
build "ffmpeg" | |
download "http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2 " "ffmpeg-snapshot.tar.bz2 " | |
cd $PACKAGES/ffmpeg* | |
CFLAGS="-I$WORKSPACE/include" LDFLAGS="-L$WORKSPACE/lib" | |
execute ./configure --arch=64 --prefix=${WORKSPACE} --extra-cflags="-I$WORKSPACE/include" --extra-ldflags="-L$WORKSPACE/lib" --extra-version=static --disable-debug --disable-shared --enable-static --extra-cflags=--static --disable-ffplay --disable-ffserver --disable-doc --enable-version3 --enable-libvpx --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libx265 --enable-avfilter --enable-gpl --enable-libopencore_amrwb --enable-libopencore_amrnb --enable-nonfree --enable-filters --enable-libvidstab --enable-runtime-cpudetect --enable-libfdk-aac | |
execute make -j 4 | |
execute make install | |
echo "" | |
echo "Building done. The binary can be found here: $WORKSPACE/bin/ffmpeg" | |
echo "" | |
read -r -p "Install the binary to your /usr/bin/ folder? [Y/n] " response | |
case $response in | |
[yY][eE][sS]|[yY]) | |
sudo cp "$WORKSPACE/bin/ffmpeg" "/usr/bin/ffmpeg" | |
sudo cp "$WORKSPACE/bin/ffprobe" "/usr/bin/ffprobe" | |
echo "Done. ffmpeg is now installed to your system" | |
;; | |
esac |
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 | |
# Created by Mirabis, Last updated: 5/18/2015 from https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu | |
echo "Clearing old files" | |
rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffserver,vsyasm,x264,x265,yasm,ytasm} | |
echo "Forcing an update" | |
apt-get update -y | |
echo "Creating dirs" | |
mkdir ~/ffmpeg_build | |
mkdir ~/ffmpeg_sources | |
echo "Checking if we should remove yasm" | |
out=`yasm --version` | |
yasm_version=`echo "$out" | cut -d " " -f 2` | |
if [[ $(version $yasm_version) < $(version '1.3.0') ]]; then | |
echo "your yasm version is too old $yasm_version wanted 1.3.0" | |
rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{yasm} | |
fi | |
echo "Checking if yasm is installed, if not - installing" | |
if [ $(dpkg-query -W -f='${Status}' yasm 2>/dev/null | grep -c "ok installed") -eq 0 ]; | |
then | |
cd ~/ffmpeg_sources | |
wget -N http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz | |
tar xzvf yasm-1.3.0.tar.gz | |
cd yasm-1.3.0 | |
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" | |
make | |
make install | |
make distclean | |
fi | |
echo "Checking if libx264 is installed, if not - installing" | |
if [ $(dpkg-query -W -f='${Status}' libx264-dev 2>/dev/null | grep -c "ok installed") -eq 0 ]; | |
then | |
cd ~/ffmpeg_sources | |
wget http://download.videolan.org/pub/x264/snapshots/last_x264.tar.bz2 | |
tar xjvf last_x264.tar.bz2 | |
cd x264-snapshot* | |
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static | |
PATH="$HOME/bin:$PATH" make | |
make install | |
make distclean | |
fi | |
echo "Checking if cmake is installed, if not - installing" | |
if [ $(dpkg-query -W -f='${Status}' cmake 2>/dev/null | grep -c "ok installed") -eq 0 ]; | |
then | |
apt-get install cmake -y; | |
fi | |
echo "Checking if mercurial is installed, if not - installing" | |
if [ $(dpkg-query -W -f='${Status}' mercurial 2>/dev/null | grep -c "ok installed") -eq 0 ]; | |
then | |
apt-get install mercurial -y; | |
fi | |
echo "installing libx265" | |
cd ~/ffmpeg_sources | |
hg clone https://bitbucket.org/multicoreware/x265 | |
cd ~/ffmpeg_sources/x265/build/linux | |
PATH="$HOME/bin:$PATH" cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="$HOME/ffmpeg_build" -DENABLE_SHARED:bool=off ../../source | |
make | |
make install | |
make distclean | |
echo "Checking if unzip is installed, if not - installing" | |
if [ $(dpkg-query -W -f='${Status}' unzip 2>/dev/null | grep -c "ok installed") -eq 0 ]; | |
then | |
apt-get install unzip -y; | |
fi | |
echo "installing libfdk-aac" | |
cd ~/ffmpeg_sources | |
wget -O fdk-aac.zip https://github.com/mstorsjo/fdk-aac/zipball/master | |
unzip fdk-aac.zip | |
cd mstorsjo-fdk-aac* | |
autoreconf -fiv | |
./configure --prefix="$HOME/ffmpeg_build" --disable-shared | |
make | |
make install | |
make distclean | |
echo "Checking if nasm is installed, if not - installing" | |
if [ $(dpkg-query -W -f='${Status}' nasm 2>/dev/null | grep -c "ok installed") -eq 0 ]; | |
then | |
apt-get install nasm -y; | |
fi | |
echo "Checking if libmp3lame-dev is installed, if not - installing" | |
if [ $(dpkg-query -W -f='${Status}' libmp3lame-dev 2>/dev/null | grep -c "ok installed") -eq 0 ]; | |
then | |
cd ~/ffmpeg_sources | |
wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz | |
tar xzvf lame-3.99.5.tar.gz | |
cd lame-3.99.5 | |
./configure --prefix="$HOME/ffmpeg_build" --enable-nasm --disable-shared | |
make | |
make install | |
make distclean | |
fi | |
echo "Checking if libopus-dev is installed, if not - installing" | |
if [ $(dpkg-query -W -f='${Status}' libopus-dev 2>/dev/null | grep -c "ok installed") -eq 0 ]; | |
then | |
cd ~/ffmpeg_sources | |
wget http://downloads.xiph.org/releases/opus/opus-1.1.tar.gz | |
tar xzvf opus-1.1.tar.gz | |
cd opus-1.1 | |
./configure --prefix="$HOME/ffmpeg_build" --disable-shared | |
make | |
make install | |
make distclean | |
fi | |
echo "installing libvpx" | |
cd ~/ffmpeg_sources | |
wget -N http://webm.googlecode.com/files/libvpx-v1.3.0.tar.bz2 | |
tar xjvf libvpx-v1.3.0.tar.bz2 | |
cd libvpx-v1.3.0 | |
PATH="$HOME/bin:$PATH" ./configure --prefix="$HOME/ffmpeg_build" --disable-examples --disable-unit-tests | |
PATH="$HOME/bin:$PATH" make | |
make install | |
make clean | |
echo "starting compile" | |
cd ~/ffmpeg_sources | |
wget -N http://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" \ | |
--bindir="$HOME/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="$HOME/bin:$PATH" make | |
make install | |
make distclean | |
hash -r | |
echo Done |
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 | |
# Created by Mirabis, Last updated: 5/18/2015 from https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu | |
echo "Deleting leftover files" | |
rm -rf ~/ffmpeg_build ~/ffmpeg_sources ~/bin/{ffmpeg,ffprobe,ffserver,vsyasm,x264,x265,yasm,ytasm} | |
sudo apt-get autoremove autoconf automake build-essential cmake libass-dev libfreetype6-dev libgpac-dev \ | |
libmp3lame-dev libopus-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev \ | |
libvorbis-dev libvpx-dev libx264-dev libxcb1-dev libxcb-shm0-dev ibxcb-xfixes0-dev mercurial texi2html zlib1g-dev | |
sed -i '/ffmpeg_build/c\' ~/.manpath | |
hash -r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment