#!/bin/bash

#sudo apt-get update

DECKINC=/home/vagrant/decklink-include

sudo apt-get -y install autoconf automake build-essential libc6-dev gcc g++ dpkg-dev autotools-dev make
sudo apt-get -y install cpp-4.8 dkms gcc-4.8 libasan0 libgcc-4.8-dev linux-compiler-gcc-4.8-x86
sudo apt-get -y linux-headers-3.16.0-4-amd64 linux-headers-3.16.0-4-common linux-headers-amd64
sudo apt-get -y install linux-kbuild-3.16 unzip

sudo apt-get -y install libfreetype6-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev
sudo apt-get -y install libass-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config
sudo apt-get -y install yasm cmake mercurial texinfo zlib1g-dev
sudo apt-get -y install libmp3lame-dev libmp3lame0 libopus-dev libopus0
sudo apt-get -y install libx264-dev libx264-142
sudo apt-get -y install libx265-dev libx265-79 libnuma1
sudo apt-get -y install libvpx-dev
sudo apt-get -y install dkms git

#sudo apt-get -y install auto-apt checkinstall

wget -N http://de.archive.ubuntu.com/ubuntu/pool/universe/x/x265/libx265-dev_1.9-3_amd64.deb
wget -N http://de.archive.ubuntu.com/ubuntu/pool/universe/x/x265/libx265-79_1.9-3_amd64.deb
sudo dpkg -i libx265-dev_1.9-3_amd64.deb libx265-79_1.9-3_amd64.deb

rm -rf ${DECKINC}
unzip -j -d ${DECKINC} Blackmagic_DeckLink_SDK_10.8.3.zip "Blackmagic DeckLink SDK 10.8.3/Linux/include/*"

tar xvf Blackmagic_Desktop_Video_Linux_10.8.4.tar Blackmagic_Desktop_Video_Linux_10.8.4/deb/amd64/desktopvideo_10.8.4a4_amd64.deb
sudo dpkg -i Blackmagic_Desktop_Video_Linux_10.8.4/deb/amd64/desktopvideo_10.8.4a4_amd64.deb

git clone https://github.com/mstorsjo/fdk-aac.git
cd fdk-aac
./autogen.sh
./configure --prefix=/usr/local --enable-shared --enable-static
make -j 4
sudo make install
sudo ldconfig

cd ~/

wget -N http://ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2

rm -rf ffmpeg-src
mkdir ffmpeg-src
cd ffmpeg-src

tar -xvjf ../ffmpeg-snapshot.tar.bz2
cd ffmpeg

./configure --prefix="/home/vagrant/ffmpeg-src/ffmpeg/" --bindir="/usr/local" \
        --pkg-config-flags="--static" \
        --extra-cflags="-I${DECKINC} -static" \
        --extra-ldflags="-L${DECKINC} -static" \
        --enable-gpl \
        --disable-shared \
        --disable-doc \
        --enable-static \
        --enable-libfdk-aac \
        --enable-libfreetype \
        --enable-libmp3lame \
        --enable-libopus \
        --enable-libtheora \
        --enable-libvorbis \
        --enable-libvpx \
        --enable-libx264 \
        --enable-nonfree \
        --enable-decklink

make -j 10

#sudo make install
#make distclean
#sudo hash -r
#sudo ldconfig
