Skip to content

Instantly share code, notes, and snippets.

@fenrir-naru
Created July 11, 2016 09:31
Show Gist options
  • Select an option

  • Save fenrir-naru/52b592b04e114982b7bf7d2e6d39462a to your computer and use it in GitHub Desktop.

Select an option

Save fenrir-naru/52b592b04e114982b7bf7d2e6d39462a to your computer and use it in GitHub Desktop.
ffmpeg_build.sh
#!/usr/bin/bash -ex
# original: http://romgrammer.blog.fc2.com/blog-entry-4.html
ffmpeg_dir=`pwd`
srcdir="$ffmpeg_dir/ffmpeg_sources"
prefix="$ffmpeg_dir/ffmpeg_build"
bindir="$ffmpeg_dir/bin"
cpus=$(( (`cat /proc/cpuinfo | awk '/^processor/{print $3}' | tail -1` + 1) / 2 ))
if [ ! -d ffmpeg_sources ]; then mkdir ffmpeg_sources; fi
cd ffmpeg_sources
ls x264* > /dev/null 2>&1 \
|| (wget https://download.videolan.org/x264/snapshots/last_stable_x264.tar.bz2 \
&& tar xjf last_stable_x264.tar.bz2 \
&& rm last_stable_x264.tar.bz2)
ls x265* > /dev/null 2>&1 \
|| (wget https://bitbucket.org/multicoreware/x265/downloads/x265_1.7.tar.gz \
&& tar xzf x265_1.7.tar.gz \
&& rm x265_1.7.tar.gz)
ls mstorsjo-fdk* > /dev/null 2>&1 \
|| (wget -O fdk-aac.tar.gz https://github.com/mstorsjo/fdk-aac/tarball/master \
&& tar xzf fdk-aac.tar.gz \
&& rm fdk-aac.tar.gz)
ls lame* > /dev/null 2>&1 \
|| (wget http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz \
&& tar xzf lame-3.99.5.tar.gz \
&& rm lame-3.99.5.tar.gz)
ls opus* > /dev/null 2>&1 \
|| (wget http://downloads.xiph.org/releases/opus/opus-1.1.tar.gz \
&& tar xzf opus-1.1.tar.gz \
&& rm opus-1.1.tar.gz)
ls libvpx* > /dev/null 2>&1 \
|| (wget http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.4.0.tar.bz2 \
&& tar xjf libvpx-1.4.0.tar.bz2 \
&& rm libvpx-1.4.0.tar.bz2)
ls ffmpeg* > /dev/null 2>&1 \
|| (wget https://www.ffmpeg.org/releases/ffmpeg-2.8.tar.bz2 \
&& tar xjf ffmpeg-2.8.tar.bz2 \
&& rm ffmpeg-2.8.tar.bz2)
#x264
(cd $srcdir/x264* \
&& if [ ! -f configure.done ]; then ./configure --prefix="$prefix" --enable-static --disable-opencl --extra-cflags='-march=native -pipe' && touch configure.done; fi \
&& make -j${cpus} \
&& make install)
#x265
(cd $srcdir/x265* && cd build/linux \
&& if [ ! -f cmake.done ]; then cmake -G "Unix Makefiles" \
-DCMAKE_INSTALL_PREFIX="$prefix" \
-DENABLE_SHARED:bool=OFF \
-DNATIVE_BUILD:bool=ON \
-DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG -pipe" \
../../source && touch cmake.done; fi \
&& make -j${cpus} \
&& make install)
#libfdk-acc
(cd $srcdir/mstorsjo-fdk-aac* \
&& if [ ! -f configure.done ]; then autoreconf -fiv \
&& ./configure --prefix="$prefix" --disable-shared CXXFLAGS='-O3 -march=native -pipe' \
&& touch configure.done; \
fi \
&& make -j${cpus} \
&& make install)
#libmp3lame
(cd $srcdir/lame* \
&& if [ ! -f configure.done ]; then ./configure --prefix="$prefix" --enable-nasm --disable-shared \
CFLAGS="-march=native -D_O_BINARY -Ofast -fomit-frame-pointer -maccumulate-outgoing-args -pipe" \
&& touch configure.done; \
fi \
&& make -j${cpus} \
&& make install)
#libopus
(cd $srcdir/opus* \
&& if [ ! -f configure.done ]; then ./configure --prefix="$prefix" --disable-shared CFLAGS='-O3 -march=native -pipe' && touch configure.done; fi \
&& make -j${cpus} \
&& make install)
#libvpx
(cd $srcdir/libvpx* \
&& if [ ! -f configure.done ]; then ./configure --prefix="$prefix" --disable-examples --disable-unit-tests --cpu=native --extra-cflags=-pipe && touch configure.done; fi \
&& make -j${cpus} \
&& make install)
#ffmpeg
(cd $srcdir/ffmpeg* \
&& if [ ! -f configure.done ]; then PKG_CONFIG_PATH="$prefix/lib/pkgconfig" ./configure \
--prefix="$prefix" \
--pkg-config-flags="--static" \
--extra-cflags="-I$prefix/include -march=native -pipe" \
--extra-ldflags="-L$prefix/lib" \
--bindir="$bindir" \
--enable-gpl \
--enable-libfdk-aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libvpx \
--enable-libx264 \
--enable-libx265 \
--enable-nonfree \
&& touch configure.done; fi \
&& make -j${cpus} \
&& make install)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment