Skip to content

Instantly share code, notes, and snippets.

@davidmroth
Last active August 13, 2018 04:06
Show Gist options
  • Save davidmroth/979284f2704ce5a4330214945213852f to your computer and use it in GitHub Desktop.
Save davidmroth/979284f2704ce5a4330214945213852f to your computer and use it in GitHub Desktop.
Compile FFMPEG for Raspberry Pi (Hardware Accelerated)
#!/bin/bash
if test -e ~/FFMpeg/.compiled; then
exit 2;
fi
# Check if root
if test $EUID -ne 0; then
echo "This script must be run as root"
exit 1
fi
cd ~
if test ! -e ~/.updated; then
apt-get update
# !! Tip !! - remove dulicates: `cat list.txt | xargs -n1 | awk '!x[$0]++' | tr "\n" " "`
apt-get install autoconf automake build-essential checkinstall libav-tools pkg-config texinfo \
libass-dev libsdl1.2-dev libfreetype6-dev x265 x264 libmp3lame-dev \
libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev \
zlib1g-dev libomxil-bellagio-dev libx264-dev libx265-dev libvpx-dev libfdk-aac-dev libfaac-dev libfdk-aac0 \
libopus-dev libopus0 libssl-dev libssl-doc libsdl2-dev libluajit-5.1-dev libxcb-shm0-dev libfontconfig1-dev libfribidi-dev \
python-docutils libbluray-dev libjpeg-dev libgnutls-dev libgnutls28-dev -y
touch .updated
fi
# Build source code for the ARM side libraries used on Raspberry Pi if needed
if ! test -e /opt/vc; then
# used to compile rpi userland
apt-get install cmake
git clone https://github.com/raspberrypi/userland
cd ~/userland
# https://github.com/raspberrypi/userland/issues/2#issuecomment-10326608
sed -i 's/if (DEFINED CMAKE_TOOLCHAIN_FILE)/if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)/g' makefiles/cmake/arm-linux.cmake
cmake -DCMAKE_BUILD_TYPE=Release
make
make install
# ensure userland libs are globaly available
echo "/opt/vc/lib" > /etc/ld.so.conf.d/rpi-userland.conf
#https://stackoverflow.com/questions/21758828/purging-and-rebuilding-ldconfig-cache
ldconfig
fi
# per: https://www.raspberrypi.org/forums/viewtopic.php?t=199775
sudo mkdir -p /usr/share/doc/lame
cd ~
if test ! -e ~/FFMpeg; then
git clone https://github.com/ffmpeg/FFMpeg --depth 1
fi
cd ~/FFMpeg
echo -e "\nConfiguring FFMpeg...\n"
# https://gist.github.com/ohanetz/73b38b87201ef06fb14d & https://www.raspberrypi.org/forums/viewtopic.php?t=199775
./configure --prefix=/usr --enable-gpl --enable-nonfree --enable-static \
--enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvpx --enable-libopus --enable-libmp3lame \
--enable-libtheora --enable-libvorbis --enable-omx --enable-omx-rpi --enable-mmal --enable-libxcb \
--enable-libfreetype --enable-libass --enable-gnutls --disable-opencl \
--arch=armel --target-os=linux \
#--extra-libs="-lnettle -lhogweed -lgmp" \
--extra-cflags="-march=armv8-a+crc -mfpu=neon-fp-armv8 -mtune=cortex-a53"
make -j4 && checkinstall make install && touch .compiled
#https://maniaclander.blogspot.com/2017/08/ffmpeg-with-pi-hardware-acceleration.html
echo "ffmpeg hold" | dpkg --set-selections
FONT_DIR=/usr/share/fonts/truetype/freefont/
mkdir -p $FONT_DIR
# Jacking default Shinobi font for video timestamping
curl -sL https://github.com/opensourcedesign/fonts/blob/master/gnu-freefont_freesans/FreeSans.ttf?raw=true -o $FONT_DIR/FreeSans.ttf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment