#!/bin/bash
#
# .---.                  .              .
# |                      |              |
# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
#
#                    Freedom in the Cloud
#
# ffmpeg functions
#
# License
# =======
#
# Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

FFMPEG_VERSION=3.1.2

function mesh_install_ffmpeg
{
    chroot "${rootdir}" apt-get -yq remove ffmpeg libav-tools
    chroot "${rootdir}" apt-get -yq install build-essential
    chroot "${rootdir}" apt-get -yq install --reinstall libmp3lame-dev libvorbis-dev libtheora-dev libspeex-dev yasm pkg-config libopenjpeg-dev libx264-dev mjpegtools libmjpegtools-dev
    mkdir -p ${rootdir}$INSTALL_DIR/ffmpeg-release
    cd ${rootdir}$INSTALL_DIR
    wget http://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.bz2
    tar xvjf ffmpeg-${FFMPEG_VERSION}.tar.bz2
    chroot ${rootdir} /bin/bash -x <<EOF
cd ${INSTALL_DIR}/ffmpeg-${FFMPEG_VERSION}
./configure --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libx264 --enable-libspeex --enable-shared --enable-pthreads --enable-libopenjpeg --enable-ffplay --enable-encoder=mjpeg --enable-decoder=mjpeg --enable-muxer=mjpeg
make
make install
EOF
    chroot "${rootdir}" apt-get install libav-tools
    chroot "${rootdir}" ldconfig
}


# NOTE: deliberately there is no "exit 0"
