Friday, August 21, 2009

ffmpeg with AMR (.amr/.3gp) and x264 on Ubuntu

A few days ago I needed to convert some AMR audio files (recorded in a phone) to a more common format -- like mp3. I found out this would be difficult since:
  • the ffmpeg from Ubuntu repositories does not suppport AMR
  • ffmpeg dropped support of libamr as it used to have - now they use lib-opencore-amr
Fortunately I found a LOT of help in Ubuntu forums, thanks mc4man for that! I am going to summarize here what I did to finally decode amr files with ffmpeg. Here we will compile ffmpeg and x264 from source code, and install them as packages so we can remove them at any time later.

Following this how-to by FakeOutdoorsman, I downloaded x264 sources (why not? let's compile to support as many formats as possible), compiled it, and downloaded ffmpeg source code:

1. Make sure you don't have any of this installed from ubuntu:
sudo apt-get purge ffmpeg x264 libx264-dev

2. Download and compile x264: (You may need to install some build tools -- see the original how-to if you don't have them)
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

3. Get libopencore-AMR-NB and libopencore-AMR-WB from DebianMultimedia. These are the urls for i386 and amd64. Download the four files libopencore-amr*, and install them with dpkg -i .

4. Download, configure and build ffmpeg. Note that the ./configure step is different than the one in the mentioned how-to -- it adds the flags for AMR.
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 --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3
make
sudo checkinstall --fstrans=no --install=yes --pkgname=ffmpeg --pkgversion "3:0.svn`date +%Y%m%d`-12ubuntu3" --default

And it's done! I am now able to transcode my files to mp3:
ffmpeg -i test.amr -f avi -vcodec xvid -acodec libmp3lame -ar 22050 test.mp3


Now if later you want to remove these packages, remove ffmpeg, x264 and the four libopencore-amr* we have installed. And also, if you ever want to upgrade with a newer source code, see the original post; they instructions are there (I have not tested that yet).

Thursday, August 6, 2009

that ol'university times...

Here is another offtopic. I found this beatiful piece of software, a kind of 'norton commander' -- ok, just a file browser for MS-DOS.... It features a recursive calculator of directory sizes, and a magnificent hex file viewer. Wow! The amazing part is that this fully written on assembler, , for an assignment a group of four friends (Abel Valente, Juan Francisco Pertino, Alejandro Miguez & me) did for the course "Taller de Arquitectura", during our 3rd year of Licenciatura en Informatica, Faculty of Informatics, University of La Plata, Argentina. One of them and me, in parallel, just remembered this work a couple of days ago: almost exactly 10 years after writing it!

Here are a few screenshots. The main screen with the directory size shown (it surprises me that Windows directory size does not overflow...):


Here, the hex viewer!


And finally, the output when exiting, with the date.... August 1999!


One more: source code.... Over 120kb and assembly, sweat and tears:


So many things learned... We will never forget the conditional jumps from the end of a loop.... to the beginning of a loop in a different procedure! And the magic trick of PUSHing and POPing all the flags to make the problem disappear.... ;)

I still can't believe we did it! Those were one of the best 34,687 bytes we ever produced! It's also hard to believe 10 years passed by. I must be getting old.