How to convert AMR files to MP3
The Nokia 7600 (And - I'm told - some Erikson phones) record in a format called "AMR". After a little digging, I was able to convert these to a usable format (MP3) on my Linux box. This is how I did it:
You will require:
- sox (via your package manager)
- lame (Or some other encoder, see below)
- The 3GPP reference converter files
The first is easy, sensible people should be able to apt-get install sox or whatever. The second may require some compiling and following instructions, the third is more complicated. The 3GPP FTP site appears to move around a bit, so links go outdated. I got it from here, but you might have more luck just searching google for "26104-520.zip".
You need to get that file, unzip it, unzip the zip inside it (It all unzips into the current directory, so you'd best put it somewhere on it's own first) and you'll get a series of c & header files. If you're using Linux (and the rest of this assumes you are) cp makefile.gcc Makefile and make it. xa.bi's site (Where I found the decoder existed) says you should do some playing with the files, but I've no idea what difference it makes. His site, btw, contains a much more advanced AMR converter than this, but I didn't need that kind of complexity. Put the resulting executables (encode and decode) somewhere useful, and remember where it is.
This is the shell script I used to make it go, you could edit it, or write your own.
#!/bin/bash
# By Aquarion - Aquarion@Aquarionics.com
# Do what you want with it, it's not rocket science.
##Change these:
#Wherever you put encode and decode when you compiled them:
CODEC=/home/aquarion/opt/mms
#Temporary directory. Chances are you've already got this set
#TEMP=/tmp/
#Where do the final MP3s go?
FINAL=mp3/
for file in *.amr; do
FILE=`echo $file | sed -e "s/.amr//"`;
echo -n "$FILE [AMR] -> [$TEMP]"
$CODEC/decoder $file $TEMP/$FILE.$TEMP > log.std 2> log.err;
echo -n " -> [WAV] "
sox -r 8000 -w -c 1 -s $TEMP/$FILE.$TEMP -r 16000 \
-w -c 1 $TEMP/$FILE.wav > log.std 2> log.err;
echo -n " -> [MP3] "
lame $TEMP/$FILE.wav $FINAL/$FILE.mp3 --silent \
--tt $FILE --ta $USER --tl Aquarionics --ty `date +%y`
echo " :-) "
rm $TEMP/$FILE.wav;
rm $TEMP/$FILE.$TEMP;
done
That script as written takes all .amr files in the current directory, turns them into .mp3 files and puts them in a subdirectory called "mp3" (which needs to exist before you run the script.)
And there you have it. If you want to convert them to oggs, you'll need to muck around with the "lame" line of the script a bit. Oh, and you'll probably want to change the album away from "Aquarionics" too.
asjkgcc:
who gives a fuck about linix. you fuck head!
Aquarion:
Athos:
Hi Aquarion,
I have this problem: I dumped a VoIP call with AMR codec and tried to convert the AMR payload with the script but…. : invalid magic number.
Could you please help me?
regularguy:
Well, apparently, 2 more adults give one about Linux than give one about your opinion.
Halfwit.
zobi:
hey goddam dickhead, sounds like you can’t even spit (non talking about merely speaking) your own language) go fuck yourself on your winblows box and let us work on some real engineering, the one that requires languages abilities as well.
f*k you
NL:
Must you do that? I mean, really?
Replying in kind to trolls like that makes us decent Linux folks look just as bad as them.
jorma:
> xa.bi’s site (Where I found the decoder existed)
> says you should do some playing with the files,
> but I’ve no idea what difference it makes.
On my redhat 9 box decoder only segfaulted when makefile and decoder.c where not edited as told in the other article. After editing decoder worked fine.
Tor:
Yeah, I also had to edit as per xa.bi’s description.
After that it worked fine (otherwise it would try to
decode from the #!AMR magic number at the start of the file (as when transfered from e.g. a S-E phone), that’s why it would crash).
I installed ’decoder’ as /usr/local/bin/amr_decoder and then used just this simple script to convert to .wav format (which can be played directly by e.g. mplayer):
#!/bin/sh
echo “Usage: $0 file.amr file.wav” exit 1if test $# -ne 2; then
fi
/usr/local/bin/amr_decoder $1 $1.raw
sox -r 8000 -w -c 1 -s $1.raw -r 16000 -w -c 1 $2
rm $1.raw
Max Littlemoore:
I am interested in going the other way.
I’m using Sarge with bluetooth and I have home grown samples I want to convert to amr to play on my my phone….
I am not too experienced with to codec tools so any help would be extremely appreciated.
A link perhaps? ... or maybe its simple and I’m missing the point.
Some help would be waxed lyrical about anyway.
Best Wishes
silvano:
the decoder always gives me the error
unknown TX frame type 8483
I tried various AMR input files, always with the same result. I’m using version 26073-600 of the
3GPP decoder.
hpn:
nice information. :)
The amr to mp3 conversion worked for me, alright. But how about vice versa?
I tried using the binary ‘encoder’, but I ain’t sure what the mode and the other options needed there ought to be. Help appreciated.
Thanks in advance.
xurizaemon:
i used ffmpeg to convert wav => amr
should be fine for mp3 => amr too
ffmpeg -i Fog.wav -acodec amr_nb -ac 1 -ar 8000 -r 8 fog.amr
anonymous:
I guess mode specifies the bitrate/channels see:
http://en.wikipedia.org/wiki/Adaptive_multi-rate_compression
the VAD options you can specify at compile time are used to select the Voice activity detection options(See GSM):
http://en.wikipedia.org/wiki/Voice_activity_detection#Specific_VAD_implementations_in_real-world_systems
CodEnemy:
good contribution (after your little digging) however, i think you should have had explained what does the three packages do instead of exposing your magic script.. which didn’t make it easier at all!!!
Pug:
Thanks for the script, and I disagree with CodEnemy – your magic script made everything work out fine. :)
Gps:
Anything for windows…pls advice
thanks
Tigggger:
Yes, For Windows I downloaded converter tool from miksoft.net. Works perfect and you can convert both ways amr to mp3 and mp3 to amr also various other sound and videaoformats.
Hope it can work for you too, Saludos desde Guatemala!
linad:
JESUS!! aint der no software to convert it :@
noonard:
I’m having a nightmae implementing this… The problem is the 3GPP decoder – it works fine for certain AMRs but I get segfaults for others (and yep – that’s after the modifications suggested). Truly bizarre, especially seeing as both seem to be in the same format to begin with!
Any ideas?!
A Nameless One:
Have you remove the optimizer? e.g. it shouldn’t say -O4 but -O2 or no -O at all.
Also the script isn’t space safe, So if th efiles got space in them that script will die. I really hope libavcodec will include this in the compiles per default in the future.
biagio:
On Fedora Core also I needed to apply the change suggested by xa.bi otherwise I had segmantation fault. Morever I had to modify the script substituting $TEMP varaible with “raw” otherwise sox get troubles (it seems that recognizes the file format by extention).
Vincenzo:
On MacOSX I had to use the modifications suggested by xabi.
humble:
some small changes were done to
1. create .raw file as sox is more happy with
that2. handle spaces in original filename.
#!/bin/bash
##Change these:
#Wherever you put encode and decode when you compiled them:
CODEC=/home/humble/mydata/mms
#Temporary directory. Chances are you’ve already got this set
TEMP=/tmp
#Where do the final MP3s go?
FINAL=mp3/
for file in *.amr; do
FILE=`echo $file | sed -e “s/.amr//” -e “s/ /_/g”`; echo -n “$FILE [AMR] -> [$TEMP]” $CODEC/decoder “$file” $TEMP/$FILE.raw > log.std 2> log.err; echo -n “ -> [WAV] ” sox -r 8000 -w -c 1 -s $TEMP/$FILE.raw -r 16000 -w -c 1 $TEMP/$FILE.wav > log.std 2> log.err ; echo -n “ -> [MP3] ” lame $TEMP/$FILE.wav $FINAL/$FILE.mp3—silent —tt $FILE—ta $USER—tl Aquarionics—ty `date +%y` echo “ :-) ” rm $TEMP/$FILE.wav; rm $TEMP/$FILE.raw;done
m4kda:
or if you want a quick solution and you are not too bothered about privacy, the online http://media-convert.com/ will convert to/from AMR format.
Cybermedievalist:
If you just need to play the files, VLC media player for Linux does that just fine. I’m posting that here simply because it was one of the first links that came up for me when I was researching this. I just decided to give VLC a whirl though and it played the .amr fine with no conversion needed.
weakish:
I have to change Makefile and decode.c before compiling as xa.bi said. Otherwise, I will get segment fault while decoding AMR files.
Nathan Zadoks:
I made one that uses piping and stuff so there’s no need for temp-files.
I needed to sudo apt-get install libsox-fmt-all first tho otherwise it said ‘sox soxio: Failed reading : unknown file type’
The code:
#!/bin/bash
if [ -z “$1” ]
then
echo Usage: $0
exit 1
fi
if [ ! -f “$1” ]
then
echo $1 doesn’t exist.
exit 2
fi
file “$1” | grep ’ Adaptive Multi-Rate Codec (GSM telephony)’
if [ $? -ne 0 ]
then
file “$1”
echo $1 isn’t an AMR file.
exit 3
fi
OUTDIR “$(dirname $1)”
OUTFILE “$(basename $1 .amr)”
OUTPUT=${OUTDIR}/${OUTFILE}.wav
if [ -f “$OUTPUT” ]
then
echo ${OUTFILE}.wav already exists.
exit 4
fi
amrnb-decoder “$1” /dev/stdout|sox -t raw -r 8000 -w -c 1 -s – -r 16000 -w -c 1
Nathan Zadoks:
Woops, little fault in it.
Any updates will be posted on my site. (www.nathan7.eu)
This is the new version:
#!/bin/bash
if [ -z “$1” ]
then
echo Usage: $0
exit 1
fi
if [ ! -f “$1” ]
then
echo $1 doesn’t exist.
exit 2
fi
file “$1” | grep ’ Adaptive Multi-Rate Codec (GSM telephony)’
if [ $? -ne 0 ]
then
file “$1”
echo $1 isn’t an AMR file.
exit 3
fi
OUTDIR “$(dirname $1)”
OUTFILE “$(basename $1 .amr)”
OUTPUT=${OUTDIR}/${OUTFILE}.wav
if [ -f “$OUTPUT” ]
then
echo ${OUTFILE}.wav already exists.
exit 4
fi
echo -n “$1”
echo -n >raw|sox>
echo “$OUTPUT”
COMMANDdec “amrnb-decoder $1 /dev/stdout”
COMMANDrec “sox -t raw -r 8000 -w -c 1 -s – -r 16000 -w -c 1 ${OUTPUT}”
echo ${COMMANDdec}|${COMMANDrec}
$COMMANDdec | $COMMANDrec