HOWTO: Convert 3GP to AVI
Sunday June 17, 2007
Some people seem to believe you need a special kind of voodoo to get videos off your mobile phone and into a media player.
With some rudimentary understanding of video codecs/formats, anyone can do this for free. That’s right – no charge, no shady shareware, no dodgy code houses charging the earth for a button – none of that thank you…
FFMPEG recently changed how it handles AMR (Adaptive Multirate Encoding – a proprietary codec), that makes things in this department far less confusing. Grab the latest source tree from their SVN), or the windows binary if you’re on windows.
If you’re compiling from source, a lot of webpages will instruct you to use —enable-amr_X. It’s rubbish, FFMPEG recently switched to using pre-built libraries (Shared Objects, or DLLs to users of Windows) for handling AMR.
Use —enable-libamr-nb —enable-libamr-wb as configure flags instead, after downloading and compiling the source to those libraries (make && make install).
Of course, all of this is outlined in the FFMPEG documentation, so refer yourself there for a finely grained guide to this.
From the command line, run:
ffmpeg -i some_input_file.3gp -f avi -acodec mp3 some_output_file.avi
You can do “man ffmpeg” on linux to see all the switches. Search that phrase on google if you can’t find the documentation in your windows build package. For example, you could use -vcodec mpeg4 to change the video encoding.
Note: if you get a warning about bitrate, just add three zeros (“000”) to the end of your parameter, so 250 becomes 250000 – alternatively, the sensible thing is to multiply by 1024 (250*1024 = 256000). -b specifies in Bits/s not KBits, so ffmpeg is just warning you that the value you entered is too low.
Update: 2008/02/06 (6th Feb)
It’s worth pointing out that in order to compile FFMPEG with libamr support, you now have to use the following flag
--enable-nonfree
In case that wasn’t clear from the standard output. If you want to see an explanation of why, please see this mailing list post by Diego Biurrun.
14 Responses to "HOWTO: Convert 3GP to AVI"
Jun 27, 05:44 PM
I’ve just realised a lot of this assumes a fair bit of background knowledge…
I guess if enough people ask for a better version I could rework some of the specifics in this article. The main point in the first place was to elucidate that ffmpeg recently changed to using pre-built libraries from AMR codecs, and there’s a lot of misinformed documentation floating about with the old —enable-amr-X flags.
Dec 20, 05:47 PM
When I run this command I get an error as follows:
ffmpeg -i 1.3gp -acodec mp3 1.avi
FFmpeg version SVN-rUNKNOWN, Copyright© 2000-2006 Fabrice Bellard, et al. configuration: —prefix=/usr —libdir=/usr/lib64 —mandir=/usr/share/man —incdir=/usr/include/ffmpeg —extra-cflags=-fPIC —enable-mp3lame —enable-libogg —enable-vorbis —enable-faad —enable-faac —enable-libgsm —enable-xvid —enable-x264 —enable-a52 —enable-a52bin —enable-dts —enable-pp —enable-shared —enable-pthreads —enable-gpl —disable-strip libavutil version: 49.1.0 libavcodec version: 51.28.0 libavformat version: 51.7.0 built on Jun 4 2007 14:17:13, gcc: 3.4.6 20060404 (Red Hat 3.4.6-8)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ’1.3gp’: Duration: 00:02:06.7, start: 0.000000, bitrate: 136 kb/s Stream #0.0(eng): Video: mpeg4, yuv420p, 160×128, 30.00 fps® Stream #0.1(eng): Audio: samr / 0×726D6173, 8000 Hz, mono
Output #0, avi, to ’1.avi’: Stream #0.0: Video: mpeg4, yuv420p, 160×128, q=2-31, 200 kb/s, 30.00 fps© Stream #0.1: Audio: 0×0000, 8000 Hz, mono, 64 kb/s
Stream mapping: Stream #0.0 -> #0.0 Stream #0.1 -> #0.1
Unsupported codec for output stream #0.1
From inspecting the file it looks like ffmpeg does not know what to do with the ‘samr’ audio codec:
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ’1.3gp’: Duration: 00:02:06.7, start: 0.000000, bitrate: 136 kb/s Stream #0.0(eng): Video: mpeg4, yuv420p, 160×128, 30.00 fps® Stream #0.1(eng): Audio: samr / 0×726D6173, 8000 Hz, mono
I am not sure how to fix this.
Dec 21, 10:19 PM
Hi Kevin,
Are you on windows or *nix? Did you compile FFMpeg yourself from source? Looking at your “configuration: ...” details, your ffmpeg binary hasn’t been compiled with libamr support.
Follow the links above to get the source code from their subversion repository. Download libamr, and use the compiled libraries by passing —enable-libamr-nb —enable-libamr-wb to your “configure” command.
If none of that makes any sense, or you’re on Windows, you might need different instructions. Post back if you’re still having difficulties…
Jan 17, 12:50 PM
Hi!
I’ve compiled ffmpeg as you write in this post, but it not support amr audio. If I list the codecs/formats with ffmpeg -formats the amr only in File formats, and bot in codecs. Here’s I get the same error message as Kevin, but I build with libamr-nb and libamr-wb:
FFmpeg version UNKNOWN, Copyright © 2000-2008 Fabrice Bellard, et al. configuration: —enable-libmp3lame -enable-libamr-nb —enable-libamr-wb libavutil version: 49.6.0 libavcodec version: 51.49.0 libavformat version: 52.4.0 libavdevice version: 52.0.0 built on Jan 17 2008 12:54:07, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from ‘MOV00158.3GP’: Duration: 00:00:56.0, start: 0.000000, bitrate: 136 kb/s Stream #0.0(jpn): Video: h263, yuv420p, 176×144 [PAR 12:11 DAR 4:3], 29.97 tb® Stream #0.1(jpn): Audio: samr / 0×726D6173, 8000 Hz, mono
WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
Output #0, flv, to ‘teszt2.flv’: Stream #0.0(jpn): Video: flv, yuv420p, 320×240 [PAR 1:1 DAR 4:3], q=2-31, 0 kb/s, 12.00 tb© Stream #0.1(jpn): Audio: libmp3lame, 22050 Hz, mono, 0 kb/s
Stream mapping: Stream #0.0 -> #0.0 Stream #0.1 -> #0.1
Unsupported codec (id=73728) for input stream #0.1
ffmpeg -formats | grep amr output is: DE amr 3gpp amr file format
no samr there
System is Linux – Debian Etch on x86
Jan 17, 05:07 PM
Hey,
Sounds like support is compiled in but the linker isn’t picking up the library. Try following this mailing list post and it should fix the situation.
For reference, mine used to pick up “samr” as the fourcc ID, but if the library is installed/linked correctly, it should give “libamr_nb” (or similar).
May 15, 02:13 AM
I had similar problems to Kevin and csibra after removing the default Ubuntu ffmpeg package under Ubuntu 8.04 and recompiling. The default package did have amr support (but no libmp3lame).
This might be obvious but the problems I had were simply caused by duplicate ffmpeg builds in the /usr/local/lib&bin and /usr/lib&bin directories. The Ubuntu path setup was different to the default ffmpeg and libamr path targets. Make sure you have either cleaned out old libraries before building or that you set the —prefix configure option when building libamr* and ffmpeg.
Aug 1, 11:34 PM
The following command (acodec argument changed), worked for me:
ffmpeg -i in.3gp -f avi -acodec libmp3lame out.avi
I also followed this page, which details how to compile the three different components from source:
http://www.mattiouz.com/blog/2007/07/02/how-to-install-ffmpeg-with-mp3-and-amr-support/
But you need to look near the end of the comments to fine the —enable-nonfree command line switch mentioned.
Oct 2, 12:44 AM
Thanks, nice simple to follow article.
I am able to convert from and to 3gp after many hours of work, However, I have an issue with some 3gp files that produce an output with the sound running twice the speed to the video. This appears to happen with Nokia 3gp files. It does not matter what the output format is. Even outputting only the audio part still does the same.
The output from ffmpeg also gives warnings such as:-
“Multiple frames in a packet from stream 1” many times although this does not always cause the sound fault.
Has anyone else had this problem with Nokia 3gp’s?
If the original file is played through Quicktime it plays fine so it has to be the libamr-nb codec.
Why should the libamr-nb codec be mis-reading these files?
Thanks
Oct 3, 04:55 AM
Hi,
In my experience this “double speed” problem isn’t unique to Nokia’s. My Sony Ericsson produces some files with this same quirk. I’m not the format expert, but I believe this might just be proprietary additions to the codec causing issues.
I know VBR audio encodings can be subject to incorrect sample rate interpolations, such that when you play a VBR file on a device that doesn’t fully support it, the file can play slowed or quickened.
What you might do in this case is separate the streams and see if you can get them to play individually at the correct speeds when converted and split. Recombine them when you have the separate streams playing correctly apart.
Dec 5, 05:42 AM
@ Jason Armstrong: You rock man. This worked perfectly for me with the libmp3lame argument. Thanks for the tip.
Jun 20, 08:52 PM
Yea, this isn’t working for me either.
At first, I get:
“Unknown encoder ‘mp3’”
Which is funny because I have Xing encoder, LAME encoder, as well as whatever radium voodoo needs to be installed for VirtualDub to allow you to use higher mp3 bitrates like 192kbps.
If I take out the mp3 part from the command line, I get:
“[mp2 @ 01CFB010]Sampling rate 8000 is not allowed in mp2”
So… I can’t do this either.
Aug 3, 05:29 PM
@ClintJCL:
use “-acodec libmp3lame” instead of “-acodec mp3” and you should be golden.
Aug 10, 04:06 AM
Great article.
I have a build of ffmpeg up and running, is there a way for me to transcode the audio for a 3gp from amr to mp3 leaving the video untouched? I find that my videos lose quality even when I don’t change the video codec, so I’d like to have a way to change the audio and leave the video as the original.
Thanks!
Aug 13, 10:02 AM
@Loren, tried using ‘-vcodec copy’? Should do the trick…