Getting ffmpeg working on Ubuntu Gutsy to encode 3gp

I got myself a new machine, installed Ubuntu 7.10 Gutsy and started installing ffmpeg.
Most of the howtos, forums and tutorials out there are kind of distorted (in regards to get ffmpeg decode/encode 3gp for older phones). Mostly because I noticed ffmpeg changes the naming convention of configure options and parameter options for AMR.

First, install the pre-requisites (make sure universe and multiverse is turned on in apt options)

sudo apt-get install liba52-dev libdts-dev libgsm1-dev libvorbis-dev libxvidcore4 libxvidcore-dev libdc1394-dev libfaac-dev liblame-dev libx264-dev libfaad2-dev libtheora-dev libsdl1.2-dev mplayer mencoder

Next, get ffmpeg. I didn't bother to install svn at the time. It's recommended to get the latest svn entries. So I just took the nightly bare sources (no subversion metadata).

tar jxvf ffmpeg-export-snapshot.tar.bz2
cd ffmpeg-export-/libavcodec

At this point, read the libamr.c file (It used to be amr.c as posted in many tutorials. Not anymore). Download the 3gpp drivers as instructed in this file. I just downloaded the float version. Get this one, it is faster.

mkdir amr_float
cd amr_float
wget http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-610.zip
unzip 26104-610.zip
unzip 26104-610_ANSI_C_source_code.zip
mv c-code/* .
cp -f makefile.gcc makefile

Once the right stuff is in place, a minor modification must take place in libavcodec/amr_float/makefile. The CFLAGS must be replaced with:

CFLAGS = -Wall -DMMS_IO -I. $(CFLAGS_$(MODE)) -D$(VAD)

Then do the usual ./configure;make;make install.

Here's my config options:
--enable-gpl --enable-pp --enable-libmp3lame --enable-libfaac --enable-libamr-nb --enable-shared --enable-pthreads --enable-x11grab --enable-liba52 --enable-libfaad --enable-libgsm --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --prefix=/usr/local

The configuration option for amr used to be --enable-amr_nb, so don't get confused with that and use --enable-libamr-nb instead.

Now, I can download youtube FLVs, encode them to 3gp files, and watch them on my mobile!
ffmpeg -i movie.avi -f 3gp -vcodec 3gp -b 100000 -s 320x176 -r 12 -acodec aac -ar 8000 -ab 16 -ac 1 movie.3gp

Here's a list of other options for other mobile devices.
ffmpeg -i movie.flv -vcodec wmv1 -acodec adpcm_ima_wav movie.wmv
ffmpeg -i videotoconvert.flv -ab 56 -ar 22050 -b 500 -s 320x240 output.mpg

For nokia n80
ffmpeg -i "$1" -ar 16000 -ac 1 -acodec aac -vcodec mpeg4 -s 352x288 -r 24 -b 350 -ab 32 "$1.3gp"

Nokia s60
ffmpeg -i movie.avi -s 172x144 -r 10 -ac 1 -b 48 -ab 12 movie.3gp

Nokia NSeries
ffmpeg -i movie.avi -f mp4 -vcodec mpeg4 -b 250000 -r 15 -s 320x176 -acodec aac -ar 24000 -ab 64 -ac 2 movie.mp4

Nokia 3250, 5500, E50, E62
ffmpeg -i movie.avi -f 3gp -vcodec 3gp -b 100000 -s 320x176 -r 12 -acodec aac -ar 8000 -ab 16 -ac 1 movie.3gp

For Ipod
ffmpeg -vcodec xvid -i input.avi -b 375 -qmax 10 -bufsize 8192 -g 300 -acodec aac -ab 96 -ac 2 -s 320×192 output.mp4

Ipod (fullscreen)
ffmpeg -i in.avi -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x240 -aspect 4:3 out.mp4

Ipod (widescreen)

ffmpeg -i in.avi -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 192 -s 320x180 -aspect 16:9 out.mp4