Something I found out today when I decided to make a quick edit to a video taken on my cellphone:  Newer GSM cell phones and devices (such as my now-dated Android G1) now tend to save video in 3GP format. This shiny new multimedia format may have many advantages, but it is not widely supported yet on mainstream desktop software, and also may encapsulate certain codecs that are not free to use. This includes the AMR audio codec, which is patent-encumbered and cannot be freely distributed. Since this is what Android and many others use in their 3GP video output, it has become a common issue.

So, apparently there are people under the impression that you can only read and edit these videos using proprietary software such as Quicktime Pro, sketchy shareware or dodgy apps from questionable code houses. For just making the very occasional simple edit to a cheesy cellphone video, it’s a lot to ask.

Fortunately, there is a good alternative. All you need  little command-line mojo and some patience.

Starting with Chez Mattiouz’s guide on installing FFmpeg with MP3 and AMR support, we will make a few updates and modifications to get a more full-featured build.

Get audio codecs (AMR for reading and MP3 for output)

MP3LAME

  1. Grab the latest sources from the MP3 LAME official site, e.g. lame-398-2.tar.gz
  2. extract it

    $ tar -xvzf lame-398-2.tar.gz
  3. change directory

    $ cd lame-398-2
  4. compile and install

    $ ./configure && make && sudo make install

The final output should indicate the binaries were installed under /usr/local

AMR

As of July 2009, FFmpeg has removed support for libamr, and replaced it with the open-source libopencore-amr. This also happens to mean that once you follow these instructions, you are free to distribute a ffmpeg (or VLC) binary that has AMR support - and though I couldn’t find one that includes it, it means probably these instructions will be outdated before long. So do a quick search for supporting binaries, and do let me know if you find one.

  1. Grab the latest sources from the Sourceforge site for opencore-amr, e.g. opencore-amr-0.1.2.tar.gz
  2. extract it

    $ tar -xvzf opencore-amr-0.1.2.tar.gz
  3. change directory

    $ cd opencore-amr-0.1.2
  4. compile and install

    $ ./configure && make && sudo make install
    

Again, you should have the new libraries under /usr/local

Configure dynamic linker

In the next step, we will compile ffmpeg. In order to include the libmp3lame and the libopencore-amr libraries that you just built, the build system needs to be able to find them under /usr/local/.  To ensure the build will work for ffmpeg, do the following:

  • create the file /etc/ld.so.conf.d/ffmpeg.conf
  • add the line /usr/local/lib
  • run ldconfig

FFmpeg

You can fetch the latest build from subversion, it is reported to be reliable

  1. $ svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
  2. change dir
    $ cd ffmpeg
  3. The final configure I ended up with, on a Fedora 11 system, was:
    $ ./configure --enable-gpl --enable-postproc --enable-x11grab --enable-avfilter --enable-avfilter-lavf --enable-libvorbis --enable-pthreads --disable-stripping --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-armvfp --disable-neon --disable-altivec --disable-vis --enable-shared --disable-static --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libmp3lame --enable-nonfree  --enable-version3

    If you get an error here about any libraries or files not found (such as libavfilter), then take out those options and try again. At a minimum you should have the AMR and MP3 libraries available, the idea basically being to get as many as possible to make a more versatile ffmpeg binary.

    If you are on Ubuntu Jaunty or similar, check this similar post on building FFmpeg with AMR support which shows which apt packages and configure options may work for you

  4. build and install
    $ make
    ...
    $ sudo make install

Now you should have ffmpeg, ffplay and ffserve under /usr/local/bin

Convert the video

Just run

$ ffmpeg -i video-from-phone.3gp -f mpeg -acodec libmp3lame out.mpeg

And you will have a working MPEG video. And after installing the libavfilter plugin, I was also able to rotate the video and create a FLV format using:

$ ffmpeg -i v.3gp -vfilters "rotate=90" -vcodec flv -f flv -acodec libmp3lame -ab 32 -ac 1 -ar 44100 -f flv -b 6000 -r 25 -y out-rot3.flv

More work to crop and edit the video is in order, when time allows. For now, the results can be seen here, a Scarlet Macaw who learned to say our daughter’s name, we found quite entertaining. Of course only my cellphone was available to take video, and I did a pretty poor job with it. So here it is:

Notes:

Leave a Comment