Skip to content

Instantly share code, notes, and snippets.

@hastinbe
Created July 31, 2015 16:56
Show Gist options
  • Select an option

  • Save hastinbe/21f4a4ec2418c491ec81 to your computer and use it in GitHub Desktop.

Select an option

Save hastinbe/21f4a4ec2418c491ec81 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# install_ffmpeg
#
# Installs the latest ffmpeg and its dependencies on Debian Wheezy for the Raspberry Pi 2
# Inspired from https://gist.github.com/faleev/3435377
#
# Author: Beau Hastings <[email protected]>
if [ $(id -u) -ne 0 ]; then
echo "This script requires root. Try 'sudo $0'"
exit 1
fi
user="$SUDO_USER"
[[ -z "$user" ]] && user=$(id -un)
home="$(eval echo ~$user)"
# Borrowed from RetroPie:
# clones or updates the sources of a repository $2 into the directory $1
function gitPullOrClone() {
local dir="$1"
local repo="$2"
local branch="$3"
[[ -z "$branch" ]] && branch="master"
mkdir -p "$dir"
# to work around a issue with git hanging in a qemu-arm-static chroot we can use a github created archive
if [[ $__chroot -eq 1 ]] && [[ "$repo" =~ github ]] && [[ ! "$repo" =~ picodrive ]]; then
local archive=${repo/.git/}
archive="${archive/git:/https:}/archive/$branch.tar.gz"
wget -O- -q "$archive" | tar -xvz --strip-components=1 -C "$dir"
return
fi
if [[ -d "$dir/.git" ]]; then
pushd "$dir" > /dev/null
git pull > /dev/null
popd > /dev/null
else
local git="git clone"
[[ "$repo" =~ github ]] && git+=" --depth 1"
[[ "$branch" != "master" ]] && git+=" --branch $branch"
echo "$git \"$repo\" \"$dir\""
$git "$repo" "$dir"
fi
}
function sources_x264() {
gitPullOrClone "$home/x264" git://git.videolan.org/x264
}
function build_x264() {
cd "$home/x264"
./configure --enable-static
make
}
function install_x264() {
sudo checkinstall --pkgname=x264 --backup=no --deldoc=yes --fstrans=no --default \
--pkgversion="3:$(./version.sh | awk -F'[" ]' '/POINT/{print $4"+git"$5}')" \
}
function sources_aac() {
wget -O- -q http://downloads.sourceforge.net/opencore-amr/fdk-aac-0.1.0.tar.gz | tar -xvz -C "$home/fdk-aac-0.1.0"
}
function build_aac() {
cd "$home/fdk-aac-0.1.0"
./configure
make
}
function install_aac() {
sudo checkinstall --pkgname=fdk-aac --pkgversion="0.1.0" \
--backup=no --deldoc=yes --fstrans=no --default
}
function sources_vp8() {
cd "$home/libvpx"
gitPullOrClone "$home/libvpx" https://chromium.googlesource.com/webm/libvpx
}
function build_vp8() {
./configure
make
}
function install_vp8() {
sudo checkinstall --pkgname=libvpx --pkgversion="1:$(date +%Y%m%d%H%M)-git" \
--backup=no --deldoc=yes --fstrans=no --default
}
function sources_ffmpeg() {
gitPullOrClone "$home/ffmpeg" git://source.ffmpeg.org/ffmpeg
}
function build_ffmpeg() {
cd "$home/ffmpeg"
./configure --extra-cflags="-mcpu=cortex-a8 -mfpu=neon" --enable-gpl --enable-libmp3lame \
--enable-libopencore-amrnb --enable-libopencore-amrwb \
--enable-librtmp --enable-libtheora --enable-libvorbis --enable-libvpx \
--enable-libx264 --enable-nonfree --enable-version3 --enable-x11grab
make
}
function install_ffmpeg() {
sudo checkinstall --pkgname=ffmpeg --pkgversion="5:$(date +%Y%m%d%H%M)-git" \
--backup=no --deldoc=yes --fstrans=no --default
}
# Remove any existing packages:
sudo apt-get -y remove ffmpeg x264 libav-tools libvpx-dev libx264-dev
# Get the dependencies (Ubuntu Server or headless users):
sudo apt-get update
sudo apt-get -y install build-essential checkinstall git libavcodec-extra libgpac-dev \
libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev librtmp-dev libtheora-dev \
libvorbis-dev pkg-config texi2html yasm zlib1g-dev libx264-dev
# Install x264
sources_x264
build_x264
install_x264
# Install AAC audio decoder
sources_aac
build_aac
install_aac
# Install VP8 video encoder and decoder
sources_vp8
build_vp8
install_vp8
# Installing FFmpeg
sources_ffmpeg
build_ffmpeg
install_ffmpeg
hash x264 ffmpeg ffplay ffprobe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment