5W site logo 5W - мой домашний сайт-блог с картинками, кино и плюшками.

ffbuild.sh.txt

#!/bin/bash
set -e

ffbuild_conf=~/.config/ffbuild.conf
if [ ! -f $ffbuild_conf ]; then
cat <<MEOW >$ffbuild_conf
#!/bin/bash
# This file contains settings for the ffbuild.sh build script

## Configuration flags for some libraries/programs
CFGFLAGS_ffmpeg=""
CFGFLAGS_mpv=""
## Single libraries/programs
ENABLE_mpv=1 # mpv
ENABLE_x264=1 # H.264 encoding
ENABLE_x264_10b=0 # 10-bit H.264 encoding
ENABLE_x265=0 # H.265 (HEVC) encoding
ENABLE_x265_10b=0 # 10-bit H.265 (HEVC) encoding
ENABLE_vpx=0 # VP8 and VP9 encoding
ENABLE_webp=0 # WebP encoding
ENABLE_mp3=0 # MP3 encoding (non-free)
ENABLE_vorbis=0 # Vorbis de-/encoding via libvorbis (ffmpeg already supports both out-of-the-box without this)
ENABLE_theora=0 # Theora encoding
ENABLE_opus=0 # Opus encoding
ENABLE_fdkaac=0 # High(er) quality AAC encoding with libfdk-aac
ENABLE_lua=1 # GUI menu for mpv
## Standalone programs
ENABLE_flac=0 # FLAC tools
ENABLE_flake=0 # Flake encoder (FLAC)
## Multiple libraries/programs
ENABLE_DVD=1 # DVD playback
ENABLE_BLURAY=0 # Bluray playback

## General settings
# By uncommenting the setting below you can override the number of jobs used for compiling
#CORES=2
# Faster cloning of git repositories (--depth=1)
FAST_GIT_CLONE=0

MEOW
echo "No configuration file found, creating one at $ffbuild_conf"
echo "You probably want to adjust some settings before running ffbuild.sh."
exit 1
fi

source $ffbuild_conf

if [ "x$CORES" == "x" ]; then
CORES=$(cat /proc/cpuinfo | grep processor | wc -l)
fi

lame_version_short=3.99
lame_version_long=3.99.5
dvdread_version=5.0.0
dvdnav_version=5.0.1
lua_version=5.2.4
flac_version=1.3.2
flake_version=0.11
fontconfig_version=2.12.1
ffmpeg_version=3.2.4
mpv_version=0.24.0
freetype2_version=2.7.1
libass_version=0.13.6
fribidi_version=0.19.7
libogg_version=1.3.2
libvorbis_version=1.3.5
libtheora_version=1.1.1
libx265_version=2.3
libvidstab_version=0.98

get_git() {
if [ -d $1 ]; then
cd $1
git pull
cd ..
else
f=""
[ $FAST_GIT_CLONE -eq 1 ] && f="$f --depth=1"
git clone $f $2 $1
fi
}

get_svn() {
if [ -d $1 ]; then
cd $1
svn up
cd ..
else
svn co $2 $1
fi
}

get_hg() {
if [ -d $1 ]; then
cd $1
hg pull
hg update
cd ..
else
hg clone $2 $1
fi
}

dl_and_extract() {
if [ ! -d $1 ]; then
if [ "x$4" != "x" ]; then
arname=$4.$3
else
arname=archive.$3
rm -f $arname
fi
[ -f $arname ] || wget "$2" -O $arname
tar xvf $arname
[ "x$4" != "x" ] && mv $4 $1
fi
}

dircd() {
mkdir -p $1
cd $1
}

conf_mk_mkinstall() {
dircd $1
if [ "x$3" != "x" ]; then
cd $SRC/$1
/bin/bash -c "$3"
cd -
fi
$SRC/$1/configure $2 --prefix=$PRFX
make -j$CORES
make install
cd ..
}

enabled() {
local a
eval a=\$ENABLE_$1
return `[ $a -eq 1 ]`
}


echo "== Retrieving sources"
dircd src

enabled mpv && echo "=== mpv"
#enabled mpv && GIT_SSL_NO_VERIFY=true get_git mpv https://github.com/mpv-player/mpv.git
enabled mpv && dl_and_extract mpv https://github.com/mpv-player/mpv/archive/v${mpv_version}.tar.gz tar.gz mpv-${mpv_version}

echo "=== ffmpeg"
#GIT_SSL_NO_VERIFY=true get_git ffmpeg https://github.com/FFmpeg/FFmpeg.git
dl_and_extract ffmpeg http://ffmpeg.org/releases/ffmpeg-${ffmpeg_version}.tar.bz2 tar.bz2 ffmpeg-${ffmpeg_version}

echo "=== freetype2"
#GIT_SSL_NO_VERIFY=true get_git freetype2 git://git.sv.nongnu.org/freetype/freetype2.git
dl_and_extract freetype2 http://download.savannah.gnu.org/releases/freetype/freetype-${freetype2_version}.tar.bz2 tar.bz2 freetype-${freetype2_version}

echo "=== fribidi"
#GIT_SSL_NO_VERIFY=true get_git fribidi http://cgit.freedesktop.org/fribidi/fribidi
dl_and_extract fribidi http://fribidi.org/download/fribidi-${fribidi_version}.tar.bz2 tar.bz2 fribidi-${fribidi_version}

echo "=== fontconfig"
#GIT_SSL_NO_VERIFY=true get_git fontconfig git://anongit.freedesktop.org/fontconfig
dl_and_extract fontconfig https://www.freedesktop.org/software/fontconfig/release/fontconfig-${fontconfig_version}.tar.bz2 tar.bz2 fontconfig-${fontconfig_version}

echo "=== libass"
#GIT_SSL_NO_VERIFY=true get_git libass https://github.com/libass/libass
dl_and_extract libass https://github.com/libass/libass/releases/download/${libass_version}/libass-${libass_version}.tar.gz tar.gz libass-${libass_version}

enabled libvidstab && echo "=== libvidstab"
enabled libvidstab && dl_and_extract libvidstab https://github.com/georgmartius/vid.stab/archive/release-${libvidstab_version}b.tar.gz tar.gz libvidstab-${libvidstab_version}

enabled BLURAY && echo "=== libaacs"
enabled BLURAY && GIT_SSL_NO_VERIFY=true get_git libaacs git://git.videolan.org/libaacs.git
enabled BLURAY && echo "=== libbdplus"
enabled BLURAY && GIT_SSL_NO_VERIFY=true get_git libbdplus git://git.videolan.org/libbdplus.git
enabled BLURAY && echo "=== libbluray"
enabled BLURAY && GIT_SSL_NO_VERIFY=true get_git libbluray git://git.videolan.org/libbluray.git
enabled DVD && echo "=== libdvdcss"
enabled DVD && GIT_SSL_NO_VERIFY=true get_git libdvdcss http://code.videolan.org/videolan/libdvdcss.git
enabled DVD && echo "=== libdvdread"
enabled DVD && dl_and_extract libdvdread http://www.videolan.org/pub/videolan/libdvdread/${dvdread_version}/libdvdread-${dvdread_version}.tar.bz2 tar.bz2 libdvdread-${dvdread_version}
enabled DVD && echo "=== libdvdnav"
enabled DVD && dl_and_extract libdvdnav http://www.videolan.org/pub/videolan/libdvdnav/${dvdnav_version}/libdvdnav-${dvdnav_version}.tar.bz2 tar.bz2 libdvdnav-${dvdnav_version}

enabled mp3 && echo "=== libmp3lame"
enabled mp3 && dl_and_extract libmp3lame http://downloads.sourceforge.net/project/lame/lame/${lame_version_short}/lame-${lame_version_long}.tar.gz tar.gz lame-${lame_version_long}

enabled opus && echo "=== libopus"
enabled opus && GIT_SSL_NO_VERIFY=true get_git libopus git://git.opus-codec.org/opus.git

enabled fdkaac && echo "=== libfdk-aac"
enabled fdkaac && GIT_SSL_NO_VERIFY=true get_git libfdk-aac https://github.com/mstorsjo/fdk-aac.git

enabled flac && echo "=== flac"
enabled flac && dl_and_extract flac http://downloads.xiph.org/releases/flac/flac-${flac_version}.tar.xz tar.xz flac-${flac_version}

enabled flake && echo "=== flake"
enabled flake && dl_and_extract flake "http://prdownloads.sourceforge.net/flake-enc/flake-${flake_version}.tar.bz2?download" tar.bz2 flake-${flake_version}

#echo "=== libogg"
#dl_and_extract libogg http://downloads.xiph.org/releases/ogg/libogg-${libogg_version}.tar.gz tar.gz libogg-${libogg_version}
#echo "=== libvorbis"
#dl_and_extract libvorbis http://downloads.xiph.org/releases/vorbis/libvorbis-${libvorbis_version}.tar.gz tar.gz libogg-${libvorbis_version}
enabled theora && echo "=== libtheora"
#enabled theora && get_svn libtheora http://svn.xiph.org/trunk/theora
#enabled theora && GIT_SSL_NO_VERIFY=true get_git libtheora https://git.xiph.org/theora.git
enabled theora && dl_and_extract libtheora http://downloads.xiph.org/releases/theora/libtheora-${libtheora_version}.tar.bz2 tar.bz2 libtheora-${libtheora_version}

enabled lua && echo "=== lua"
enabled lua && dl_and_extract lua http://www.lua.org/ftp/lua-${lua_version}.tar.gz tar.gz lua-${lua_version}
sed -i 's/$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline"/$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline -lncurses"/g' `pwd`/lua/src/Makefile

enabled vorbis && echo "=== libvorbis"
enabled vorbis && get_svn libvorbis http://svn.xiph.org/trunk/vorbis/
enabled vpx && echo "=== libvpx"
enabled vpx && GIT_SSL_NO_VERIFY=true get_git libvpx https://chromium.googlesource.com/webm/libvpx
enabled webp && echo "=== libwebp"
enabled webp && GIT_SSL_NO_VERIFY=true get_git libwebp https://chromium.googlesource.com/webm/libwebp
enabled x264 && echo "=== libx264"
enabled x264 && GIT_SSL_NO_VERIFY=true get_git libx264 git://git.videolan.org/x264.git

enabled x265 && echo "=== libx265"
#enabled x265 && get_hg libx265 https://bitbucket.org/multicoreware/x265
enabled x265 && dl_and_extract libx265 https://bitbucket.org/multicoreware/x265/downloads/x265_libx265_version.tar.gz tar.gz libx265-${libx265_version}

echo "== Building"
cd ..
mkdir -p target
export PRFX=`pwd`/target
export SRC=`pwd`/src
export BLD=`pwd`/build
export PKG_CONFIG_PATH=$PRFX/lib/pkgconfig
export LD_LIBRARY_PATH=$PRFX/lib
export PATH=$PRFX/bin:$PATH
dircd build

echo "=== fribidi"
#conf_mk_mkinstall fribidi "--enable-static --disable-shared --without-glib"
conf_mk_mkinstall fribidi "--without-glib"

echo "=== freetype2"
conf_mk_mkinstall freetype2 "--disable-static" "./autogen.sh"

echo "=== fontconfig"
conf_mk_mkinstall fontconfig "--disable-docs --enable-libxml2 --sysconfdir=/etc --localstatedir=/var"

echo "=== libass"
#conf_mk_mkinstall libass "--enable-static --disable-shared" "./autogen.sh"
conf_mk_mkinstall libass ""

enabled libvidstab && echo "=== libvidstab"
enabled libvidstab && cd $SRC/libvidstab
enabled libvidstab && cmake -DCMAKE_INSTALL_PREFIX:PATH=$PRFX $CONFF $SRC/libvidstab/source
enabled libvidstab && make
enabled libvidstab && make install
enabled libvidstab && cd ..

enabled BLURAY && echo "=== libaacs"
enabled BLURAY && conf_mk_mkinstall libaacs "" "./bootstrap"

enabled BLURAY && echo "=== libbdplus"
enabled BLURAY && conf_mk_mkinstall libbdplus "" "./bootstrap"
enabled BLURAY && echo "=== libbluray"
enabled BLURAY && conf_mk_mkinstall libbluray "" "./bootstrap"
enabled DVD && echo "=== libdvdcss"
enabled DVD && conf_mk_mkinstall libdvdcss "" "autoreconf -i"
enabled DVD && echo "=== libdvdread"
enabled DVD && conf_mk_mkinstall libdvdread ""
enabled DVD && echo "=== libdvdnav"
enabled DVD && conf_mk_mkinstall libdvdnav ""

enabled mp3 && echo "=== libmp3lame"
enabled mp3 && conf_mk_mkinstall libmp3lame "--enable-nasm"

enabled opus && echo "=== libopus"
enabled opus && conf_mk_mkinstall libopus "--enable-custom-modes" "./autogen.sh"
enabled fdkaac && echo "=== libfdk-aac"
enabled fdkaac && conf_mk_mkinstall libfdk-aac "" "./autogen.sh"
enabled flac && echo "=== flac"
enabled flac && conf_mk_mkinstall flac ""
if enabled flake; then
echo "=== flake"
# flake does not compile when not built from src dir
cd $SRC/flake
./configure --disable-debug --prefix=$PRFX
make # no -j$CORES because the Makefile sucks
make install
cd -
fi

#echo "=== libogg"
#conf_mk_mkinstall libogg "" ""
#echo "=== libvorbis"
#conf_mk_mkinstall libvorbis "" ""
enabled theora && echo "=== libtheora"
enabled theora && conf_mk_mkinstall libtheora "--disable-examples" "./autogen.sh; make distclean; true"

if enabled lua; then
echo "=== lua"
cd $SRC/lua
make linux -j$CORES
make INSTALL_TOP=$PRFX install
cat >$PRFX/lib/pkgconfig/lua.pc <<MEOW # Create a pkgconfig file for mpv to find lua
V=5.2
R=$lua_version

prefix=$PRFX
INSTALL_BIN=\${prefix}/bin
INSTALL_INC=\${prefix}/include
INSTALL_LIB=\${prefix}/lib
INSTALL_MAN=\${prefix}/man/man1
INSTALL_LMOD=\${prefix}/share/lua/\${V}
INSTALL_CMOD=\${prefix}/lib/lua/\${V}
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${prefix}/include

Name: Lua
Description: An Extensible Extension Language
Version: \${R}
Requires:
Libs: -L\${libdir} -llua -lm
Cflags: -I\${includedir}

MEOW
cd -
fi
#echo "=== v4l-utils"
#conf_mk_mkinstall v4l-utils "" "autoreconf -if"
enabled vorbis && echo "=== libvorbis"
enabled vorbis && conf_mk_mkinstall libvorbis "" "./autogen.sh && make distclean"
enabled vpx && echo "=== libvpx"
enabled vpx && conf_mk_mkinstall libvpx "--enable-shared --enable-runtime-cpu-detect --enable-postproc --enable-vp8 --enable-vp9"
enabled webp && echo "=== libwebp"
enabled webp && conf_mk_mkinstall libwebp "--enable-libwebpmux --enable-libwebpdemux --enable-libwebpdecoder" "./autogen.sh"
enabled x264 && echo "=== libx264"
enabled x264 && CONFF="--enable-shared --disable-lavf"
enabled x264_10b && CONFF="$CONFF --bit-depth=10"
enabled x264 && conf_mk_mkinstall libx264 "$CONFF"

enabled x265 && echo "=== libx265"
enabled x265 && dircd libx265
enabled x265 && CONFF=""
enabled x265_10b && CONFF="-DHIGH_BIT_DEPTH=1"
enabled x265 && cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$PRFX $CONFF $SRC/libx265/source
enabled x265 && make -j$CORES
enabled x265 && make install
enabled x265 && cd ..

echo "=== ffmpeg"
dircd ffmpeg
#CONFF="--enable-libass --enable-libfreetype --enable-gnutls --disable-debug --disable-doc --enable-pic --enable-static --disable-shared"
CONFF="--enable-fontconfig --enable-libass --enable-libfreetype --enable-gnutls --disable-debug --disable-doc --enable-pic --enable-nonfree --enable-shared --disable-static --enable-opengl"

enabled libvidstab && CONFF="$CONFF --enable-libvidstab --enable-gpl"
enabled x264 && CONFF="$CONFF --enable-libx264 --enable-gpl"
enabled x265 && CONFF="$CONFF --enable-libx265 --enable-gpl"
enabled vpx && CONFF="$CONFF --enable-libvpx"
enabled webp && CONFF="$CONFF --enable-libwebp"
enabled mp3 && CONFF="$CONFF --enable-libmp3lame --enable-nonfree"
enabled vorbis && CONFF="$CONFF --enable-libvorbis"
enabled theora && CONFF="$CONFF --enable-libtheora"
enabled opus && CONFF="$CONFF --enable-libopus"
enabled fdkaac && CONFF="$CONFF --enable-libfdk-aac --enable-nonfree"
enabled BLURAY && CONFF="$CONFF --enable-libbluray"
$SRC/ffmpeg/configure $CFGFLAGS_ffmpeg --prefix=$PRFX --cc=gcc-63 $CONFF
unset CONFF
make -j$CORES
make install
cd ..

enabled mpv && echo "=== mpv"
enabled mpv && dircd mpv
enabled mpv && cd $SRC/mpv
enabled mpv && ./bootstrap.py
enabled mpv && ./waf configure $CFGFLAGS_mpv \
--prefix=$PRFX \
--check-c-compiler=gcc-63 \
--lua=52 \
--enable-lcms2 \
--enable-libass \
--enable-lua

enabled mpv && ./waf build -j$CORES
enabled mpv && ./waf install
enabled mpv && cd -

cd ..
echo "Done."