Author:
R. Koucha
Last update:
05-Apr-2011
Go back to previous page
Go back to home page
How to support AMR with ffmpeg and
ffplay
Introduction
Most smartphones (e.g. the Samsung Player Addict) provide the ability
to record video clips. But the audio stream uses the AMR (Adaptive
Multi
Rate Narrowband or Wideband) codec. This codec is rarely
supported by the video players in the standard Linux distributions.
ffmpeg is able to support AMR provided that it is compiled to support
it.
Then with a ffmpeg correctly installed, it is possible to convert the
audio track into other well known formats (like mpeg2 or mpeg3).
The following presents the steps to install ffmpeg and its player
ffplay to be able to hear the audio track of the video clips
coming from smartphones. Those steps supposes that the Linux
distribution is an Ubuntu.
Download AMR codecs
> mkdir build_ffmpeg
> cd build_ffmpeg
> ls -l
-rw-r--r-- 1 koucha koucha 868977 2011-04-05 09:44 opencore-amr-0.1.2.tar.gz
> tar xvfz opencore-amr-0.1.2.tar.gz
> ls -l
drwxr-xr-x 8 koucha koucha 4096 2011-04-05 09:47 opencore-amr-0.1.2
-rw-r--r-- 1 koucha koucha 868977 2011-04-05 09:44 opencore-amr-0.1.2.tar.gz
- Make and install the libraries:
> cd opencore-amr-0.1.2
> ./configure
> make
- Install it with the super user rights (hence the "sudo" command):
> sudo make install
> ls -l /usr/local/lib/libopencore-amr*
-rw-r--r-- 1 root root 1040916
2011-04-05 09:51 /usr/local/lib/libopencore-amrnb.a
-rwxr-xr-x 1 root root 1005 2011-04-05 09:51
/usr/local/lib/libopencore-amrnb.la
lrwxrwxrwx 1 root root 26 2011-04-05
09:51 /usr/local/lib/libopencore-amrnb.so ->
libopencore-amrnb.so.0.0.2
lrwxrwxrwx 1 root root 26 2011-04-05
09:51 /usr/local/lib/libopencore-amrnb.so.0 ->
libopencore-amrnb.so.0.0.2
-rwxr-xr-x 1 root root 639212 2011-04-05 09:51
/usr/local/lib/libopencore-amrnb.so.0.0.2
-rw-r--r-- 1 root root 344770 2011-04-05 09:51
/usr/local/lib/libopencore-amrwb.a
-rwxr-xr-x 1 root root 1005 2011-04-05 09:51
/usr/local/lib/libopencore-amrwb.la
lrwxrwxrwx 1 root root 26 2011-04-05
09:51 /usr/local/lib/libopencore-amrwb.so ->
libopencore-amrwb.so.0.0.2
lrwxrwxrwx 1 root root 26 2011-04-05
09:51 /usr/local/lib/libopencore-amrwb.so.0 ->
libopencore-amrwb.so.0.0.2
-rwxr-xr-x 1 root root 237529 2011-04-05 09:51
/usr/local/lib/libopencore-amrwb.so.0.0.2
Installation of the SDL library
The SDL library is necessary for ffplay
player. If not installed,
ffplay would not be compiled
during the ffmpeg installation.
> sudo apt-get install libsdl-dev
Installation of additional libraries
The following libraries are useful to make ffmpeg manage more formats:
> sudo apt-get install libgsm1-dev
> sudo apt-get install libmp3lame-dev
> sudo apt-get install libvorbis-dev
Build and installation of ffmpeg/ffplay
- Go back to the directory build_ffmpeg
> ls -l
drwxr-xr-x 8 koucha koucha 4096 2011-04-05 09:47 opencore-amr-0.1.2
-rw-r--r-- 1 koucha koucha 868977 2011-04-05 09:44 opencore-amr-0.1.2.tar.gz
> svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg-svn
> ls -l
drwxr-xr-x 15 koucha koucha 4096 2011-04-05 10:00 ffmpeg-svn
drwxr-xr-x 8 koucha koucha 4096 2011-04-05 09:47 opencore-amr-0.1.2
-rw-r--r-- 1 koucha koucha 868977 2011-04-05 09:44 opencore-amr-0.1.2.tar.gz
> cd ffmpeg-svn
> sudo ./configure --enable-gpl --enable-pthreads --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-libmp3lame --enable-libfaac --enable-libgsm --enable-libvorbis --enable-nonfree
> sudo make
> sudo make install
To verify that ffmpeg has been
built correctly:
> /usr/local/bin/ffmpeg
FFmpeg version SVN-r19564, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --enable-gpl --enable-pthreads --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-libmp3lame --enable-libfaac --enable-libgsm--enable-libvorbis --enable-nonfree
[...]
Note: if the AMR
libraries are not found at installation time, update the
LD_LIBRARY_PATH environment variable with the path of those libraries
Example of video translation
Here is a video generated by my Samsung Player Addict smartphone:
> /usr/local/bin/ffmpeg -i video.mp4
[...]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
Duration: 00:00:28.50, start: 0.000000, bitrate: 1032 kb/s
Stream #0.0(und): Video: mpeg4, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 30 tbr, 1k tbn, 30 tbc
Stream #0.1(und): Audio: libopencore_amrnb, 8000 Hz, 1 channels, s16
At least one output file must be specified
Let's translate the audio stream of this video from AMR to MP3:
> /usr/local/bin/ffmpeg -i video.mp4 -sameq -ar 22050 -acodec libmp3lame video.avi
[...]
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
Duration: 00:00:28.50, start: 0.000000, bitrate: 1032 kb/s
Stream #0.0(und): Video: mpeg4, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 30 tbr, 1k tbn, 30 tbc
Stream #0.1(und): Audio: libopencore_amrnb, 8000 Hz, 1 channels, s16
Output #0, avi, to 'video.avi':
Stream #0.0(und): Video: mpeg4, yuv420p, 640x480 [PAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 30 tbn, 30 tbc
Stream #0.1(und): Audio: libmp3lame, 22050 Hz, 1 channels, s16, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 550 fps= 84 q=0.0 Lsize= 16835kB time=28.50 bitrate=4839.1kbits/s
video:16555kB audio:223kB global headers:0kB muxing overhead 0.338204%
Verification of the audio format:
> /usr/local/bin/ffmpeg -i video.avi
[...]
Input #0, avi, from 'video.avi':
Duration: 00:00:28.57, start: 0.000000, bitrate: 4825 kb/s
Stream #0.0: Video: mpeg4, yuv420p, 640x480 [PAR 1:1 DAR 4:3], 30 tbr, 30 tbn, 30 tbc
Stream #0.1: Audio: mp3, 22050 Hz, 1 channels, s16, 64 kb/s
About the
author
The author is an engineer in computer sciences located in France. He
can be contacted here or
you can have
a look at his WEB
home page.