Skip to content

Instantly share code, notes, and snippets.

@dustMason
Forked from prashantmaurice/install-ffmpeg-amazon-linux.sh
Last active January 11, 2022 15:51
Show Gist options
  • Save dustMason/59ace48a844a066bd2167a03734704a5 to your computer and use it in GitHub Desktop.
Save dustMason/59ace48a844a066bd2167a03734704a5 to your computer and use it in GitHub Desktop.
How to compile ffmpeg on Amazon Linux (EC2) for use on AWS Lambda
#!/bin/bash
# Author : Hemanth.HM
# Email : hemanth[dot]hm[at]gmail[dot]com
# License : GNU GPLv3
#
function useage()
{
cat << EOU
Useage: bash $0 <path to the binary> <path to copy the dependencies>
EOU
exit 1
}
#Validate the inputs
[[ $# < 2 ]] && useage
#Check if the paths are vaild
[[ ! -e $1 ]] && echo "Not a vaild input $1" && exit 1
[[ -d $2 ]] || echo "No such directory $2 creating..."&& mkdir -p "$2"
#Get the library dependencies
echo "Collecting the shared library dependencies for $1..."
deps=$(ldd $1 | awk 'BEGIN{ORS=" "}$1\
~/^\//{print $1}$3~/^\//{print $3}'\
| sed 's/,$/\n/')
echo "Copying the dependencies to $2"
#Copy the deps
for dep in $deps
do
echo "Copying $dep to $2"
cp "$dep" "$2"
done
echo "Done!"
#!/bin/sh
# Based on gist.github.com/gboudreau/install-ffmpeg-amazon-linux.sh
# and https://trac.ffmpeg.org/wiki/CompilationGuide/Centos
if [ "`/usr/bin/whoami`" != "root" ]; then
echo "You need to execute this script as root."
exit 1
fi
cat > /etc/yum.repos.d/centos.repo<<EOF
[centos]
name=CentOS-6 – Base
baseurl=http://mirror.centos.org/centos/6/os/x86_64/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
enabled=1
priority=1
protect=1
includepkgs=SDL SDL-devel gsm gsm-devel libtheora theora-tools
EOF
rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
rpm -Uhv http://ec2-23-22-86-129.compute-1.amazonaws.com/pub/sam/1.3/el6/x86_64/SAM_brew_latest/toplink/packages/libraw1394/2.0.4/1.el6/x86_64/libraw1394-2.0.4-1.el6.x86_64.rpm
rpm -Uhv http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
yum -y update
yum -y install glibc gcc gcc-c++ autoconf automake libtool git make nasm pkgconfig
yum -y install SDL-devel a52dec a52dec-devel alsa-lib-devel faac faac-devel faad2 faad2-devel
yum -y install freetype-devel giflib gsm gsm-devel imlib2 imlib2-devel lame lame-devel libICE-devel libSM-devel libX11-devel
yum -y install libXau-devel libXdmcp-devel libXext-devel libXrandr-devel libXrender-devel libXt-devel
yum -y install libogg libvorbis vorbis-tools mesa-libGL-devel mesa-libGLU-devel xorg-x11-proto-devel zlib-devel
yum -y install libtheora theora-tools
yum -y install ncurses-devel
yum -y install libdc1394 libdc1394-devel
yum -y install amrnb-devel amrwb-devel opencore-amr-devel
cd /opt
rm -rf fdk-aac
git clone --depth 1 git://https://github.com/mstorsjo/fdk-aac
cd fdk-aac
autoreconf -fiv
./configure --prefix="$HOME/ffmpeg_build" --disable-shared
make
make install
echo
cd /opt
rm -rf lame-3.99.6
curl -L -O http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --disable-shared --enable-nasm
make
make install
echo
yum -y remove yasm
cd /opt
rm -rf yasm-1.2.0
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
tar xzfv yasm-1.2.0.tar.gz && rm -f yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" && make install
export "PATH=$PATH:$HOME/bin"
cd /opt
rm -rf ffmpeg
git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
git checkout release/3.0
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig" ./configure --prefix="$HOME/ffmpeg_build" \
--extra-cflags="-I$HOME/ffmpeg_build/include -Bstatic" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib -ldl -Bstatic" \
--bindir="$HOME/bin" \
--pkg-config-flags="--static" \
--enable-gpl \
--enable-nonfree \
--enable-libfdk_aac \
--enable-libmp3lame
make
make install
cp $HOME/bin/ffmpeg /usr/bin/
cp $HOME/bin/ffprobe /usr/bin/
# Test the resulting ffmpeg binary
ffmpeg -version
@dustMason
Copy link
Author

dustMason commented Jun 8, 2017

Updated to follow current official guide. Includes libfdk_aac and libmp3lame for performing audio conversions.

Use deps.sh script to gather shared lib dependencies if needed. If deploying to AWS Lambda, place these libs in /lib at root of your packaged function.

@wobeng
Copy link

wobeng commented Apr 25, 2018

Hi @dustMason

can you expand on

Use deps.sh script to gather shared lib dependencies if needed. If deploying to AWS Lambda, place these libs in /lib at root of your packaged function.

@ullee
Copy link

ullee commented Jan 11, 2022

Line 39 at typo. You have to omit "git://"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment