Home > 1 > Install FFMPEG correctly on ubuntu 9.0.4

Install FFMPEG correctly on ubuntu 9.0.4

Getting the Dependencies
1. Uninstall x264, libx264-dev, and ffmpeg if they are already installed. Open a terminal and run the following:

Code:
sudo apt-get purge ffmpeg x264 libx264-dev

2. Next, get all of the packages you will need to install FFmpeg and x264 (you may need to enable the universe and multiverse repositories):

Code:
sudo apt-get update
sudo apt-get install build-essential subversion git-core checkinstall yasm texi2html libfaac-dev libfaad-dev libmp3lame-dev libsdl1.2-dev libtheora-dev libx11-dev libxvidcore4-dev zlib1g-dev

Install x264
3. Get the most current source files from the official x264 git repository, compile, and install. You can run “./configure –help” to see what features you can enable/disable. If you are behind a firewall or unable to use git, then daily source tarballs are also available.

Code:
cd
git clone git://git.videolan.org/x264.git
cd x264
./configure
make
sudo checkinstall --fstrans=no --install=yes --pkgname=x264 --pkgversion "1:0.svn`date +%Y%m%d`-0.0ubuntu1" --default

Install FFmpeg
4. Get the most current source files from the official FFmpeg svn, compile, and install. Run “./configure –help” to see what features you can enable/disable. If you are behind a firewall or unable to use subversion, then nightly FFmpeg snapshots are also available.

Code:
cd
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-nonfree --enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libx264 --enable-libxvid --enable-x11grab
make
sudo checkinstall --fstrans=no --install=yes --pkgname=ffmpeg --pkgversion "3:0.svn`date +%Y%m%d`-12ubuntu3" --default

That’s it for installation. You can keep the ~/x264 and ~/ffmpeg directories if you later want to update the source files to a new revision. See “Updating Your Installation” below for more details.

Using FFmpeg and x264
The easiest method for high quality video encoding is by using the libx264 presets that are included with FFmpeg.

Two-Pass encode using the fastfirstpass and hq presets:

Code:
ffmpeg -y -i input.avi -pass 1 -vcodec libx264 -vpre fastfirstpass -b 512k -bt 512k -threads 0 -f mp4 -an /dev/null && ffmpeg -i input.avi -pass 2 -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre hq -b 512k -bt 512k -threads 0 -f mp4 output.mp4

You can add options such as frame size (for example: -s 640×480) or tweak my example settings to customize your encode.

One-pass CRF (Constant Rate Factor) using the hq preset:

Code:
ffmpeg -i input.avi -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre hq -crf 22 -threads 0 output.mp4

FFmpeg x264 encoding guide has more info on the differences of two-pass and CRF. Also see FFmpeg libx264 presets for more preset descriptions and usage.

Two-pass iPod 640×480 using the fastfirstpass, normal, and ipod640 presets:

Code:
ffmpeg -y -i input.avi -pass 1 -vcodec libx264 -vpre fastfirstpass -vpre ipod640 -b 512k -bt 512k -s 640x480 -threads 0 -f ipod -an /dev/null && ffmpeg -i input.avi -pass 2 -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre normal -vpre ipod640 -b 512k -bt 512k -s 640x480 -threads 0 -f ipod output.mp4

You may have to use qt-faststart, MP4Box, or AtomicParsley to make the video iTunes friendly. I don’t use iTunes or iPod so I can’t test this. More info and other usage examples: iPod Video Guide.

Updating Your Installation
You may eventually want to update to the newest revisions of FFmpeg and x264 if there are any major developments or changes:

Code:
sudo apt-get purge ffmpeg x264
cd ~/x264
make distclean
git pull
./configure
make
sudo checkinstall --fstrans=no --install=yes --pkgname=x264 --pkgversion "1:0.svn`date +%Y%m%d`-0.0ubuntu1" --default
cd ~/ffmpeg
make distclean
svn update
./configure --enable-gpl --enable-nonfree --enable-pthreads --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libx264 --enable-libxvid --enable-x11grab
make
sudo checkinstall --fstrans=no --install=yes --pkgname=ffmpeg --pkgversion "3:0.svn`date +%Y%m%d`-12ubuntu3" --default

Keep in mind that the option names used in configuring FFmpeg often change between revisions. This also applies to encoding options. If your encoding script breaks between revisions this is the first thing to look for.

Reverting Changes Made by This Tutorial
To remove FFmpeg/x264 and any changes made from this tutorial:

Code:
sudo apt-get purge x264 ffmpeg build-essential subversion git-core checkinstall yasm texi2html libfaac-dev libfaad-dev libmp3lame-dev libsdl1.2-dev libtheora-dev libx11-dev libxvidcore4-dev zlib1g-dev

Lastly, delete the ffmpeg and x264 directories in your home folder.

Additional Resources

Recent Tutorial Updates

2009-07-14: Added libx11-dev as a dependency to make –enable-x11grab actually work. Removed the “Optional Dependency” section and just added those dependencies (libsdl1.2-dev for ffplay and zlib1g-dev for png and some other encoders) into the main dependency section.

2009-06-12: Added –enable-x11grab to FFmpeg configuration to allow recording of the screen / desktop / X window manager.

Let me know if you have any recommendations or corrections. If you have problems include your Ubuntu version, the FFmpeg command, and the full FFmpeg output.


Last edited by FakeOutdoorsman; July 14th, 2009 at 08:18 PM..
Categories: 1
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.