Sunday, June 28, 2009

HOWTO: Easily enable MP3, MPEG4, AAC, and other restricted encoding in FFmpeg

A common question is "why doesn't the repository FFmpeg convert to mp3, aac, mpeg4, etc?". Ubuntu doesn't make it very clear to the general user as to why to repo FFmpeg is so limited or how to fix this issue. This is reflected in the number of forum questions relating to this topic.

Why is FFmpeg from the repository so limited?
Legal reasons. Some software is limited due to geographical differences in software patents, legal restrictions on free speech, and restrictions on certain technologies. Ubuntu sidesteps these legal restrictions by not including some restricted packages by default. Users must install these packages on their own. See Restricted Formats Ubuntu Community Documentation and FFmpeg License and Legal Considerations for more details.

How do I fix FFmpeg?
There are several options:
A. Compile FFmpeg yourself
B. Install the "unstripped" libraries from the repository
C. Install the ubuntu-restricted-extras package
D. Install FFmpeg from Medibuntu
A. Compiling FFmpeg yourself (for all Ubuntu versions)
The official FFmpeg answer is to compile it yourself, giving you the power to get what you want with the benefits of the most recent FFmpeg revision. This is an excellent solution and is explained here:

HOWTO: Install and use the latest FFmpeg and x264

However, this isn't for everyone, especially beginners. Sometimes you want an official package that works right now; with a minimum of fuss. Off to the other options...

B. Installing the "unstripped" libraries from the repository
This is the easiest option for Intrepid and Jaunty users and is not available for prior Ubuntu versions. FFmpeg from the repository does not include many restricted encoders, formats, and codecs including: h261, h263, h263p, aac (libfaac), mp3 (libmp3lame), h264 (libx264), xvid (libxvid), mpeg2video, mpeg4, msmpeg4, msmpeg4v1, and msmpeg4v2. You can fix this by installing the "unstripped" FFmpeg libraries that will enable these restricted encoders. Open up Terminal (Applications -> Accessories -> Terminal) and enter:

Ubuntu Jaunty Jackalope 9.04
sudo apt-get install ffmpeg libavcodec-unstripped-52
Ubuntu Intrepid Ibex 8.10
sudo apt-get install ffmpeg libavcodec-unstripped-51
Alternatively, you can search for these packages in the Synaptic Package Manager.

C. Installing the ubuntu-restricted-extras package
Another option for Jaunty and Ibex is to install the ubuntu-restricted-extras package. This is a metapackage, which means that it will install multiple packages including the "unstripped" FFmpeg libraries. This is a sledgehammer approach, especially if you are bandwidth limited, and will install a large amount of other packages that you may not want. To install this package, open up Terminal (Applications -> Accessories -> Terminal) and enter:

sudo apt-get install ffmpeg ubuntu-restricted-extras
D. Installing FFmpeg from Medibuntu
This option is only available for Ubuntu Hardy Heron 8.04 and Ubuntu Gutsy Gibbon 7.10. Medibuntu is a third-party repository that contains a number of packages that are unable to be included in the official Ubuntu repositories. To install FFmpeg from Medibuntu open Terminal (Applications -> Accessories -> Terminal) and run the following:

sudo wget`lsb_release -cs`.list --output-document=/etc/apt/sources.list.d/medibuntu.list; sudo apt-get -q update; sudo apt-get --yes -q --allow-unauthenticated install medibuntu-keyring; sudo apt-get -q update
This huge command will install the repository information to your computer then update and authenticate the new repository. Now install FFmpeg:

sudo apt-get install ffmpeg
That's it. Now you have a non-crippled version of FFmpeg.

Here's an example to encode a mp3 file:
ffmpeg -i inputfile.mp4 -acodec libmp3lame -ab 128k outputfile.mp3
Undoing Changes Made By This Guide
B. Uninstalling the "unstripped" libraries
sudo apt-get remove ffmpeg libavcodec-unstripped-5*
C. Uninstalling the ubuntu-restricted-extras package
sudo apt-get remove ubuntu-restricted-extras
D. Uninstalling FFmpeg and the Medibuntu Repository
sudo apt-get autoremove ffmpeg medibuntu-keyring; sudo rm /etc/apt/sources.list.d/medibuntu.list; sudo apt-get update
Let me know if you have any questions or comments. Thanks to andrew.46 for suggesting this guide.

No comments: