Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to compile ffmpeg on Amazon Linux (EC2)
#!/bin/sh
# Based on instructions found here: http://wiki.razuna.com/display/ecp/FFMpeg+Installation+on+CentOS+and+RedHat#FFMpegInstallationonCentOSandRedHat-InstallX264
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 libdc1394 libdc1394-devel libraw1394-devel
EOF
rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
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
wget http://downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
tar xzvf xvidcore-1.3.2.tar.gz && rm -f xvidcore-1.3.2.tar.gz
cd xvidcore/build/generic
./configure --prefix="$HOME/ffmpeg_build" && make && make install
cd /opt
wget http://downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.gz
tar xzvf libogg-1.3.1.tar.gz && rm -f libogg-1.3.1.tar.gz
cd libogg-1.3.1
./configure --prefix="$HOME/ffmpeg_build" --disable-shared && make && make install
cd /opt
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz
tar xzvf libvorbis-1.3.4.tar.gz && rm -f libvorbis-1.3.4.tar.gz
cd libvorbis-1.3.4
./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-shared && make && make install
cd /opt
wget http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz
tar xzvf libtheora-1.1.1.tar.gz && rm -f libtheora-1.1.1.tar.gz
cd libtheora-1.1.1
./configure --prefix="$HOME/ffmpeg_build" --with-ogg="$HOME/ffmpeg_build" --disable-examples --disable-shared --disable-sdltest --disable-vorbistest && make && make install
cd /opt
wget http://downloads.sourceforge.net/opencore-amr/vo-aacenc-0.1.2.tar.gz
tar xzvf vo-aacenc-0.1.2.tar.gz && rm -f vo-aacenc-0.1.2.tar.gz
cd vo-aacenc-0.1.2
./configure --prefix="$HOME/ffmpeg_build" --disable-shared && make install
yum -y remove yasm
cd /opt
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
git clone http://git.chromium.org/webm/libvpx.git
cd libvpx
git checkout tags/v1.3.0
./configure --prefix="$HOME/ffmpeg_build" --disable-examples && make && make install
cd /opt
git clone git://git.videolan.org/x264.git
cd x264
./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static && make install
export LD_LIBRARY_PATH=/usr/local/lib/:$HOME/ffmpeg_build/lib/
echo /usr/local/lib >> /etc/ld.so.conf.d/custom-libs.conf
echo $HOME/ffmpeg_build/lib/ >> /etc/ld.so.conf.d/custom-libs.conf
ldconfig
cd /opt
git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg
git checkout release/2.2
PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig"
export PKG_CONFIG_PATH
./configure --prefix="$HOME/ffmpeg_build" --extra-cflags="-I$HOME/ffmpeg_build/include" --extra-ldflags="-L$HOME/ffmpeg_build/lib" --bindir="$HOME/bin" \
--extra-libs=-ldl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvpx --enable-libfaac \
--enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libvo-aacenc --enable-libxvid --disable-ffplay \
--enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads --arch=x86_64 && make install
# Test the resulting ffmpeg binary
cp $HOME/bin/ffmpeg /usr/bin/
ffmpeg -v
@mr-deamon

This comment has been minimized.

Copy link

@mr-deamon mr-deamon commented Oct 22, 2014

The very last line will - at least with version 2.2.9 of ffmpeg - fail with "Missing argument for option 'v'.". You can fix this by using -version instead of -v

Thank you very much for this script!!

@bateller

This comment has been minimized.

Copy link

@bateller bateller commented Jan 20, 2015

Awesome tutorial / script.

Just a note... x264 is prohibited for commercial use without licensing.

@markdrury

This comment has been minimized.

Copy link

@markdrury markdrury commented Jan 31, 2015

Very helpful -- thanks for sharing this!

@kopurando

This comment has been minimized.

Copy link

@kopurando kopurando commented Feb 26, 2015

In case you're fine with a binary:
http://ffmpeg.gusari.org/static/64bit/ffmpeg.static.64bit.latest.tar.gz
works on EC2 64bit

@thushan85

This comment has been minimized.

Copy link

@thushan85 thushan85 commented Mar 4, 2015

Thanks a lot :)

@mainfraame

This comment has been minimized.

Copy link

@mainfraame mainfraame commented Jun 8, 2015

Awesome! Thank you!

  • You're missing the inclusion of libmp3lame.

cd /opt
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" --disable-shared --enable-nasm && make && make install

@ahojchris

This comment has been minimized.

Copy link

@ahojchris ahojchris commented Jul 14, 2015

Great Gist!

One minor update... the location of the libvpx repo has changed, so you'll want to replace this line:

git clone http://git.chromium.org/webm/libvpx.git

with this:

git clone https://chromium.googlesource.com/webm/libvpx
@juandelacruz-calvo

This comment has been minimized.

Copy link

@juandelacruz-calvo juandelacruz-calvo commented Sep 30, 2015

Thank you for the script, just perfect

@iumesh

This comment has been minimized.

Copy link

@iumesh iumesh commented Nov 4, 2015

ffmpeg version n2.2.16-11-gbeaf272
built on Nov 4 2015 10:20:43 with gcc 4.8.3 (GCC) 20140911 (Red Hat 4.8.3-9)
configuration: --prefix=/root/ffmpeg_build --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --extra-libs=-ldl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvpx --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libvo-aacenc --enable-libxvid --enable-ffplay --enable-ffprobe --enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads --arch=x86_64
libavutil 52. 66.100 / 52. 66.100
libavcodec 55. 52.102 / 55. 52.102
libavformat 55. 33.100 / 55. 33.100
libavdevice 55. 10.100 / 55. 10.100
libavfilter 4. 2.100 / 4. 2.100
libswscale 2. 5.102 / 2. 5.102
libswresample 0. 18.100 / 0. 18.100
libpostproc 52. 3.100 / 52. 3.100

i changed line 97, 98 and added --enable-ffprobe and --enable-ffplay but i cant find ffprobe and ffplay

can you tell me how to install ffprobe and ffplay

@davidwu0709

This comment has been minimized.

Copy link

@davidwu0709 davidwu0709 commented Jan 9, 2016

awesome, thanks.

@acl0056

This comment has been minimized.

Copy link

@acl0056 acl0056 commented Feb 4, 2016

@ahojchris Thank you so much!!!

@acl0056

This comment has been minimized.

Copy link

@acl0056 acl0056 commented Feb 5, 2016

@iumesh ffprobe and ffmpeg are in the /opt/ffmpeg directory. You can link or copy them to /usr/bin

@morrislaptop

This comment has been minimized.

Copy link

@morrislaptop morrislaptop commented Mar 8, 2016

needs new git URL for libvpx - https://chromium.googlesource.com/webm/libvpx

@morrislaptop

This comment has been minimized.

Copy link

@morrislaptop morrislaptop commented Mar 8, 2016

And ffmpeg -version at the end :)

@hoalongntc

This comment has been minimized.

Copy link

@hoalongntc hoalongntc commented Mar 11, 2016

You saved me dude!

@robertBojor

This comment has been minimized.

Copy link

@robertBojor robertBojor commented Mar 22, 2016

Awesome, thanks man!

@immortalize

This comment has been minimized.

Copy link

@immortalize immortalize commented Apr 15, 2016

for some reason, there was a missing package called libraw1394 that failed the dependency, I've googled it and found on 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/ installeed it manually with rpm -Uvh ... that made it passed

@immortalize

This comment has been minimized.

Copy link

@immortalize immortalize commented Apr 15, 2016

and I think a git repo is dead (fatal: http://git.chromium.org/webm/libvpx.git/info/refs not valid: is this a git repository?)
I've replaced git clone http://git.chromium.org/webm/libvpx.git with git clone https://github.com/webmproject/libvpx.git hoping that's same

@alfonsodev

This comment has been minimized.

Copy link

@alfonsodev alfonsodev commented May 26, 2016

@immortalize you are right, the command yum -y install libdc1394 libdc1394-devel fails with ...

--> Finished Dependency Resolution
Error: Package: libraw1394-devel-2.0.4-1.el6.x86_64 (centos)
           Requires: libraw1394 = 2.0.4-1.el6
Error: Package: libdc1394-2.1.2-3.4.el6.x86_64 (centos)
           Requires: libraw1394.so.11()(64bit)
Error: Package: libraw1394-devel-2.0.4-1.el6.x86_64 (centos)
           Requires: libraw1394.so.11()(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

Thanks for you solution

@alfonsodev

This comment has been minimized.

Copy link

@alfonsodev alfonsodev commented May 27, 2016

I created a fork, it works as for today 27.05.16 in a fresh "amzn-ami-hvm-2015.09.1.x86_64-gp2" instance
The fork https://gist.github.com/alfonsodev/4471bc4fcbac2c36c91c278c876ea7b8 contains the fixes mentioned above,

  • repo libvpx
  • libraw1394
  • missing libmp3lame

Additionally

  • removed x264 as is prohibited for commercial use without licensing
  • added fdk-aac
  • removed libvo-aacenc
  • ffmpeg updated to v3.0
@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Aug 24, 2016

repoforge/rpms#375 RepoForge is a dead project

@prashantmaurice

This comment has been minimized.

Copy link

@prashantmaurice prashantmaurice commented Dec 2, 2016

WORKING FORK AS OF 2.12.2016 :
Yet another fork i created with few edits for my use after a changing code to run in AWS EC2 instances created by EBS
https://gist.github.com/prashantmaurice/07e52f970cbb1f6d10b5165344623b04

Steps:

  1. clone https://gist.github.com/prashantmaurice/07e52f970cbb1f6d10b5165344623b04 into machine
  2. cd 07e52f970cbb1f6d10b5165344623b04
  3. chmod 777 install-ffmpeg-amazon-linux.sh
  4. ./install-ffmpeg-amazon-linux.sh

Tested in :
EC Containers(Linux) of AWS

Fixes:
Removed Deprecated Options
Fixed with changes of RELEASE/3.0

@vitaly-zdanevich

This comment has been minimized.

Copy link

@vitaly-zdanevich vitaly-zdanevich commented Oct 10, 2017

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