# Script ffmpeg compile for Mageia 7 Linux
# Alvaro Bustos, thanks to Hunter.

urpmi nasm

# Create a temporary directory for sources.
SOURCES=$(mkdir ~/ffmpeg_sources)
cd ~/ffmpeg_sources

# Download the necessary sources.
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
# wget https://www.nasm.us/pub/nasm/releasebuilds/2.14/nasm-2.14.tar.bz2
# curl -#LO ftp://ftp.videolan.org/pub/x264/snapshots/last_stable_x264.tar.bz2
wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20180720-2245.tar.bz2
# git clone --depth 1 https://github.com/mstorsjo/fdk-aac
wget https://netcologne.dl.sourceforge.net/project/opencore-amr/fdk-aac/fdk-aac-0.1.6.tar.gz
wget https://pkgs.rpmfusion.org/repo/pkgs/free/lame/lame-3.99.5.tar.gz/84835b313d4a8b68f5349816d33e07ce/lame-3.99.5.tar.gz
wget http://www.mirrorservice.org/sites/distfiles.macports.org/libopus/opus-1.2.1.tar.gz
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.gz
wget http://ftp.osuosl.org/pub/xiph/releases/vorbis/libvorbis-1.3.6.tar.gz
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz
git clone --depth 1 https://chromium.googlesource.com/webm/libvpx.git
wget http://ffmpeg.org/releases/ffmpeg-4.0.tar.gz

# Unpack files
for file in `ls ~/ffmpeg_sources/*.tar.*`; do
tar -xvf $file
done

cd yasm-*/
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && make && sudo make install && make distclean; cd ..

# cd nasm-*/
# ./autogen.sh 
# ./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" 
# make
# make install 
# cd ..

cp /root/bin/nasm /usr/local/bin

cd x264-*/
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static && make && make install && make distclean; cd ..

cd fdk-aac-*/
autoreconf -fiv && ./configure --prefix="$HOME/ffmpeg_build" --disable-shared && make && make install && make distclean; cd ..

cd lame-*/
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm && make && make install && make distclean; cd ..

cd opus-*/
autoreconf -fiv && ./configure --prefix="$HOME/ffmpeg_build" --disable-shared && make && make install && make distclean; cd ..

cd libogg-*/
./configure --prefix="$HOME/ffmpeg_build" --disable-shared && make && make install && make distclean; cd ..

cd libvorbis-*/
LDFLAGS="-L$HOME/ffmeg_build/lib" CPPFLAGS="-I$HOME/ffmpeg_build/include" ./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared && make && make install && make distclean; cd ..

cd libtheora-*/
./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-examples --disable-shared --disable-sdltest --disable-vorbistest && make && make install; cd ..

cd libvpx
./configure --prefix="$HOME/ffmpeg_build" --disable-examples && make && make install && make clean; cd ..

cd ffmpeg-*/
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" --pkg-config-flags="--static" --enable-gpl --enable-nonfree --enable-libfdk_aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libtheora && make && make install && make distclean && hash -r; cd ..

cd ~/bin
cp ffmpeg ffprobe x264 lame /usr/local/bin

echo "FFmpeg Compilation is Finished!"






