#!/bin/bash
CORE_DIR=$PWD
FFMPEG_VER=3.3
TP_DIR=$CORE_DIR/ext/third_party
FFMPEG_DIR=$TP_DIR/ffmpeg-$FFMPEG_VER
FFMPEG_LIB=$TP_DIR/ffmpeg-lib

LIB_DIR=/usr/local/lib

apt-get install -y libavcodec-dev

cd $TP_DIR
tar xvfj ffmpeg-3.3.tar.bz2

cd $CORE_DIR
cd $FFMPEG_DIR

./configure --disable-debug --enable-libopus --enable-shared --disable-filters --enable-filter=aresample --enable-filter=asetnsamples --enable-filter=asplit --disable-encoders --disable-decoders --enable-decoder=libopus --enable-decoder=mp3  --enable-decoder=pcm_s32le --enable-decoder=pcm_s24le --enable-decoder=pcm_s16le --enable-decoder=adpcm_g722 --enable-decoder=pcm_u8 --enable-decoder=adpcm_ms --enable-encoder=libopus --enable-encoder=pcm_s32le --enable-encoder=pcm_s24le --enable-encoder=pcm_s16le --enable-encoder=adpcm_g722 --enable-encoder=pcm_u8 --enable-encoder=adpcm_ms --disable-protocols --enable-protocol=rtp --enable-protocol=tcp --enable-protocol=udp --enable-protocol=file --enable-protocol=pipe --disable-demuxers --enable-demuxer=mp3 --enable-demuxer=rtp --enable-demuxer=wav --disable-muxers --enable-muxer=mp3 --enable-muxer=rtp --enable-muxer=wav --enable-muxer=tee --disable-parsers --enable-parser=mpegaudio

make && make install

find $FFMPEG_DIR -name '*.so.*' -exec cp {} $LIB_DIR \;

ldconfig

cp $LIB_DIR/libavcodec.* $FFMPEG_LIB
cp $LIB_DIR/libavdevice.* $FFMPEG_LIB
cp $LIB_DIR/libavfilter.* $FFMPEG_LIB
cp $LIB_DIR/libavformat.* $FFMPEG_LIB
cp $LIB_DIR/libavutil.* $FFMPEG_LIB
cp $LIB_DIR/libpostproc.* $FFMPEG_LIB
cp $LIB_DIR/libswresample.* $FFMPEG_LIB
cp $LIB_DIR/libswscale.* $FFMPEG_LIB

cp $FFMPEG_DIR/ffmpeg $FFMPEG_LIB
cp $FFMPEG_DIR/ffprobe $FFMPEG_LIB
cp $FFMPEG_DIR/ffserver $FFMPEG_LIB
