niemueller.de::home niemueller.de
Open Software. Open Knowledge.




 

Convert Video to 3GPP

What is this about?

In todays mobile phones the 3GPP standard is widely in use for videos on the phone. Newer camera mobiles can take movies from their integrated camera which are encoded in 3GPP (usually with suffix .3gp). 3GPP stands for 3rd Generation Partnership Project and is a consortium which agrees on standards for telecommunications. The video standard is one spec that came out. See their page at http://www.3gpp.org for more information. This page describes how to convert regular video files like AVI or MPEG with freely available open source tools like mplayer and ffmpeg into a GP3 file. I have tested this on Fedora Core 2 and copied the files to my Nokia 6230 (and watched them of course :-) This page is not meant for novice users. I will not answer questions via email about this. Fight it yourself to get it working. For Windoze users there is a tool called Nokia Multimedia Converter that you can download from Forum Nokia at http://www.forum.nokia.com. You will need to register but the download itself is free. It is a Java application that converts the videos with a graphical interface. I have not tested if it can be used on Linux. I prefer the open source tools.

Theory

I do not know the video standard completely but here are some information that you should know when dealing with those videos (this is not yet integrated into the different programs and so you will need to do some handwork, see below): The video is encoded in H.263 (for more info ask Google) and the audio in narrow-band AMR (adaptive multi-rate) audio codec (for more info see [RFC 3267]).

What you need

You will need the following packages. If you are using a distro like Fedora Core you can get these easily from third-party apt repositories like [FreshRPMS]. These packages have many dependencies by themselves. Read their pages on what that is or use a package management system that cares for you about that.

Setup of MPlayer and FFMPEG

Fedora 7

For Fedora 7 life is pretty easy. You can use the [Livna] and [FreshRPMs] RPM repositories. I personally tend to install (almost) all media software from Livna. Mixing libraries from both repositories easily leads to problems. Instal amrnb and amrnb-devel from FreshRPMs?. Then get the source package for ffmpeg from the repository that you like better, I personally used Livna. Install the source RPM (I assume you know how to build RPMs). Then edit SPECS/ffmpeg.spec and add "--enable-amr-nb" to the configure line. Build the rpm with rpmbuild -bb ffmpeg.spec and install the resulting packages ffmpeg and ffmpeg-libs. Now you can skip the rest of the installation section and continue to the encoding section.

Older systems with source patching

Install MPlayer. I have used a 1.0. FFMPEG needs some additional files that are not part of the distribution (I guess because of licensing issues). I have tested this with FFMPEG version 0.4.8. Get the source code and unpack it. If you use version 0.4.8 read on below. Otherwise read the notes here on how to determine which files you need: Go to the directory, open the file "configure" and search for "amr" or "3gpp". At the very end of the file you should find some notes that tells you which files to get. There should be a note like
  echo "AMR NB FLOAT NOTICE ! Make sure you have downloaded TS26.104"
  echo "REL-5 V5.1.0 from "
  echo "http://www.3gpp.org/ftp/Specs/latest/Rel-5/26_series/26104-510.zip"
  echo "and extracted the source to libavcodec/amr_float"
The name before the .zip (here 26104-510) is the interesting part. The path is wrong. If you use version 0.4.8 you need 26104-510.

Do this for the version you determined:
  • go to http://www.3gpp.org/ftp/Specs/archive/
  • open the folder that is mentioned last in the URL, here: 26_series
  • open the folder matchin your version, for the version mentioned: 26.104
  • get the zip mentioned, for the example: 26104-510.zip
Now unpack the FFMPEG source and do:
mkdir -p libavcodec/amr_float
cd libavcodec/amr_float
unzip 26104-510.zip
unzip 26104-510_ANSI_C_source_code.zip
cp -f makefile.gcc makefile
Now go to the ffmpeg dir and configure as usual with an additional "--enable-amr_nb" argument. Example: ./configure --enable-amr_nb. make and make install as usual. Note for RPM users: Get the src RPM (if you use apt: apt-get source ffmpeg) and install it. Go to /usr/src/redhat/SPECS and edit ffmpeg.spec. Add at the top where it says Source Source1: 26104-510.zip. Copy the zip file to /usr/src/redhat/SOURCES Add the following to the %prep section after the %setup macro:
mkdir -p libavcodec/amr_float
cd libavcodec/amr_float
unzip %SOURCE1
unzip 26104-510_ANSI_C_source_code.zip
cp -f makefile.gcc makefile
And add the --enable-amr_nb flag to the configure line. Now rpmbuild -ba ffmpeg.spec && rpm -Uvh --force ../RPMS/i386/ffmpeg*. (you should install ffmpeg before this via apt or something like that to resolve all dependencies!).

Encode Videos

Now that you got everything setup we can finally encode some nice videos :-) To get an actual example I will describe here how to convert Undo from [Platige Image] for your mobile. You can get the video on their page at http://www.undomovie.com/ Also have a look at "The Cathedral" which is even more impressive! Get the undo.mpg file and store in in a directory. Go to that directory. Now we do the following
mencoder undo.mpg -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vf expand=176:144,scale=176:-2 -o movie.avi -ofps 12
This will scale the movie down to QCIF resolution (176x144), remove the sound (will care about that later) and store it as MPEG4 in an AVI container with 12 frames per second. You may want to play with the frames per second. I found 12 frames per second to be just fine. Do not change the resolution however. The Nokia 6230 that I have also only has 128x128 pixel display, but 3GPP only defines a small set of resolutions supported. QCIF is one of them and should be used. The later steps will fail if you change this.

Now we want to get the sound from the video:
mplayer -vo null -ao pcm -af resample=8000,volume=+4db:sc undo.mpg
This extracts the audio from the file and resamples the sound to 8 kHz (seems to be a requirement for AMR) and makes the sound 4 dB louder. It also applies a soft clip filter. The result is a file called audiodump.wav that contains the sound.

Now we put both files together and merge it into a 3GPP file:
ffmpeg -i movie.avi -i audiodump.wav -b 48 -ac 1 -ab 12 -map 0.0 -map 1.0 undo.3gp
We use ffmpeg to merge the two inputs movie.avi and audiodump.avi into the file undo.3gp. We use a bitrate of 48 kbit/sec for the video and 12 kbit/sec for the audio. We only use one audio channel (mono) and map the video and audio streams appropriately into the new file.

Done. Now you can copy the file to your mobile (see NokiaCopyViaBluetooth) and enjoy the show :-)

Enhancements

In some cases you may want to apply a few enhancements to the video material you have got. In Undo you may have noticed the black bars. These could be removed for more real video information. For Undo this is not really useful, since this involves scaling and this makes the video look narrow. For other vids it may fit better. In general what you need are images that can be easily scaled down to QCIF (176x144) or SQCIF (128x96) resolutions (for the Nokia 6230, other phones, other resolutions... But 3GPP/H.263 is pretty strict about allowed resolutions (see this [page about H.263] for a listing. I guess all of these are supported by 3GPP, but I have no clue which cell phones can decode which resolutions). To find out what to crop mencoder has s nice filter that will tell you just that:
mencoder undo.mpg -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vf cropdetect
This will give you output lines like
crop area: X: 512..0  Y: 202..207  (-vf crop=-512:6:512:202)00 [0:0]
So wwe create a cropped.avi with the cropped movie:
mencoder undo.mpg -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vf crop=-512:6:512:20 -o cropped.avi -ofps 12
Now you can rescale the movie. To actually make use of the space and stretch the movie we will use the following command:
mencoder cropped.avi -nosound -ovc lavc -lavcopts vcodec=mpeg4 -vop expand=176:144,scale=176:144 -o movie.avi -ofps 12
Then extract the sound and merge the files using ffmpeg as described above.
    Home     Contents     Search     View other revisions     Recent changes    




Top 5 Pages
Wiki
WebLog
SquidGuard Webmin Module
Link Pile
Onager




Palm Software
UniMatrix UniMensa UniSorter
UniChat OHS Mobile Onager


My Bookshelf




Valid XHTML 1.1!

RSS Copyright © 2000-2009 by Tim Niemueller