See into S60
» Subscribe
» Favorite Links
» What is S60?
» Freeware & Trials
» S60 devices
» Hints and tips

» About this blog
» Application development (24)
» Applications (36)
» Devices (21)
» Games (7)
» General (40)
» Imaging (9)
» Music (17)
» Python (3)
» Video (40)
» Tommi's Reports from Wonderland
» Voice of S60
» Creating Carbide C++
» S60 Multimedia Blog
» The Convergence Zone
» Web Browser for S60 Blog
» Consumed by S60
» Java for S60
» Mobile Web Server
» Mobile Security
» See into S60
» Business2GO
» Nokia Podcasting Application Blog
» New Mobile TV Receiver Accessory
» Video Podcast Roundup to watch on Nseries
» And the TIPA goes to...
» Top Classic Smartphones
» GPS Location Tagging Integrated into the Camera
» July 2008
» May 2008
» April 2008
» March 2008
» February 2008
» January 2008
» December 2007
» November 2007
» October 2007
» September 2007
» August 2007
» June 2007
» May 2007
» April 2007
» March 2007
» February 2007
» January 2007
» December 2006
» November 2006
» October 2006
» September 2006
» August 2006
» July 2006
» June 2006
» May 2006
» April 2006
» March 2006
» February 2006
» January 2006
Subscribe
Kevin's Jaiku Badge
Carol's Jaiku Badge

Links
November 29, 2006 Video transcoding using ffmpeg Posted by Oren at 03:25 PM | Categories: Video

My colleague Florin Lohan has been playing with ffmpeg, a free Linux command-line tool that can transcode your videos into mobile-friendly formats. Jukka wrote earlier about SmartMovie, a commercial (i.e. not free) PC program that also transcodes videos for viewing on your mobile device. ffmpeg sounds like a better option for non-PC users and other lovers of open source software. It ships as part of most Linux distributions. You can also download and compile the code yourself.

Read on for the details of how it works. (Nov. 30: Updated the audio parameters)

When transcoding a video, you will need to specify a combination of file format, audio codec and video codec for the target video that matches the capabilities of your S60 phone. For most S60 3rd Edition phones, a good combination to use is MPEG-4 video and AAC audio in an mp4 file format. Higher-end phones such as the N93 or N95 also support the H.264 video codec, which delivers high-quality video in a much smaller file.

You will also need to specify the frame size of the video output. S60 3rd edition phones, for example, may have one of these screen resolutions:
- 208x176 (normal, or legacy resolution)
- 416x352 (double resolution)
- 320x240 (QVGA)
- 208x208 (Nokia 5500)

For more information about the supported formats and screen sizes of Nokia devices, consult the Forum Nokia multimedia reference page.

Screen size

Ideally, the width of the transcoded movie should match the width of the device's screen. This is not always possible; for example, devices with double resolution do not support a video frame width of more than 352 (i.e. the width in portrait mode). When you watch the video on the device, the player will scale the image to the entire screen, regardless of the actual pixel width of the video data. (In practice, this means that the best phones for video playback are those with the QVGA resolution, in case you are wondering what to buy).

You will need to calculate the height of the movie yourself, since the S60 media player can't interpret the aspect ratio parameters encoded into the video file. You can also use the Media Info function in the VLC player to extract aspect ratio data. The width/height ratio of the output video should match the aspect ratio of the original movie. Florin also recommends that the height of the transcoded movie be multiple of 16; he saw some artifacts at the bottom of the screen when using other values.

For a 16:9 movie, then, here are Florin's recommendations for target frame size:
- 208x176 (normal, or legacy resolution): 208x112
- 416x352 (double resolution): 352x192
- 320x240 (QVGA): 320x176

Video and audio parameters

As mentioned above, a good format for most S60 3rd Edition devices is:
- MPEG-4 video: 250 kbit/sec at 15 frames per second (fps)
- AAC audio: stereo audio, 24 kHz (or 48 kHz), 64 kbps. (Note: 24 kHz and 48 kHz are in general better values for most S60 phones instead of 22kHz or 44kHz, because of features of the device hardware.)
- MP4 file format

This translates to the following ffmpeg command line (for a 320x176 frame size):

ffmpeg -i movie.avi -f mp4 -vcodec mpeg4 -b 250000 -r 15 -s 320x176 -acodec aac -ar 24000 -ab 64 -ac 2 movie.mp4

where
-i movie.avi : input file
-f mp4 : target file format (mp4)
-vcodec mpeg4 : target video codec (MPEG-4 Video)
-b 250000 : bitrate of the transcoded video. Older versions use kbits/s (-b 250 in this case).
-r 15 : target framerate. You can skip this parameter, and use the framerate of the input file.
-s 320x176 : framesize of the transcoded video.
-acodec aac : target audio codec (AAC)
-ar 24000 : target audio sampling rate in Hz. 48000 is also a good value, but may require a higher audio bitrate as well.
-ab 64 : target audio bitrate in kbits/sec
-ac 2 : target audio channels (2 for stereo, 1 for mono)

For phones such as the Nokia 3250, 5500, E50 and E62, you will need to specify a lower-quality output, as the device hardware has less horsepower than Nseries devices. For these phones, Florin suggests:
- 3GPP video: 100 kbit/sec at 12 fps
- AAC audio: mono, 8kHz, 16 kbps.
- 3GP file format

Or in command line form:

ffmpeg -i movie.avi -f 3gp -vcodec 3gp -b 100000 -s 320x176 -r 12 -acodec aac -ar 8000 -ab 16 -ac 1 movie.3gp

A few more notes about ffmpeg. Florin had to download and compile ffmpeg himself, as the one that came with the Linux distribution did not support AAC output streams. You can include AAC In the build by adding parameters to the "configure" command:

./configure --enable-faac --enable-faad --enable-gpl

You may want to enable some other encoders and decoders, depending on what formats your movies use. A more
complete configuration line is as follows, but it requires your system to have more libraries.

./configure --enable-faac --enable-faad --enable-mp3lame --enable-x264 --enable-a52 --enable-dts --enable-gpl

Let me know if you get this working, and what your experience is.

-Oren


Permalink |

Comments

If you run on Mac, be sure to try this one ... http://www.ffmpegx.com/

Posted by: Jonathan Greene | November 29, 2006 04:32 PM

If you need to produce old-school 3gp videos with AMR audio codecs (or need to convert those), ffmpeg can do that too but you have to hop through a few more loops.

Type 'ffmpeg -formats' to see what formats you have compiled in. (Just in case you have AMR already.)

You need to obtain AMR codec source code from 3GPP. Have a look at libavcodec/amr.c in the ffmpeg tree and follow instructions there as to where to put the source. For AMR-NB, get the newest from http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/ and for AMR-WB, http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/. Enable compilation of the latter with --enable-amr_wb.

Hope this helps.

Posted by: Anonymous | November 30, 2006 03:11 AM

If you use windows why not try MediaCoder. Available free from sourceforge.

http://mediacoder.sourceforge.net/

Posted by: Skavenger | November 30, 2006 11:36 AM

@Skavenger: that looks like a good solution as well. I found a mobile phone How-to on the Wiki.

Posted by: Oren Levine | November 30, 2006 01:07 PM

As commented further above there are also nice utilities that do the transcoding with a nice GUI. Incidentally, I tried MediaCoder today to transcode some TV recordings for my N93 and have put my experiences on my blog: http://mobilesociety.typepad.com/mobile_life/2006/11/converting_vide.html

Posted by: Martin | November 30, 2006 03:44 PM

Ciao Oren,

here a free tool based that use the ffmpeg library
http://www.erightsoft.com/SUPER.html

I used the ffmpeg library on Linux and it's really useful.

Alessandro

Posted by: Alessandro | November 30, 2006 08:08 PM

Thanks for posting this. I'm a linux user running ffmpeg. I had managed to get useful mp4 working from ffmpeg just by leeching various internet posts, but it's very nice to see a dedicated, organized discussion.

Posted by: Jay_cee | December 21, 2006 04:45 PM

Hi,

I have been using several (including yours) methods for converting divx to realplayer with no luck. The soft does not recongnize the format. When I was trying to see directly from a divx, I got at least the sound ! I have other mp4 files (iPod, PSP) but same bad luck nothing works on my E60.
Any guess ?

btw i'm on Mac

Posted by: fred | January 4, 2007 08:30 AM

fred, just gussing here but if your mp4 files contain AVC that's not supported by E60.

Posted by: Jukka Eklund | January 4, 2007 11:06 AM

Ok thanks, finally found a workaround by exporting through Quicktime as a 3gp file...works fine but maybe not the best quality but for a mobile phone should be fine

Posted by: fred | January 4, 2007 12:58 PM

Anyone have that working with the N80? I tried a couple times and no luck. I only interested in getting ffmpeg of mencoder working.

Posted by: Eric | January 5, 2007 12:06 AM

Hello Eric,
I was able to make movies playing for N80.
Can you please post the ffmpeg command line you are trying?

Posted by: Florin | January 17, 2007 09:42 AM

To encode for using DivX Player: ffmpeg -i movie.avi -f avi -vtag DX50 -deinterlace -s 320x240 -b 512000 -acodec mp3 -ab 128 -y movie2.avi

If -vtag DX50 option is not present DivX Player will no recognize videos

Posted by: David | January 29, 2007 03:24 PM

I've experimented a lot with Super http://www.erightsoft.com/SUPER.html

It seems to be hard to find settings for the E62 that give both good video quality and synchronised sound. It appears that settings for the E61 produce video that chokes the E62.

Any advice on how to get great video *and* synced sound on the E62?

Posted by: Steve | February 2, 2007 08:08 PM

I've found that with the latest version of ffmpeg, you need to give the audio bitrate in bps, not kbps (so it's gone the same way as the video one)

Posted by: Nick Burch | July 10, 2007 12:07 AM

Found good one here :
http://blogger.rukker.org/2006/07/12/enable-mp3-and-amr-support-in-ffmpeg-ubuntudebian/
tried the step by step guide but no luck, then i scrap the resulting ffmpeg installation, download the precompiled package, install it, then everything works like a charm... 3gp, mp4 you name it, converts from and to many other formats...
I notice that the precompiled package has amr_nb, mp3 and mp4 audio enabled...works on my ubuntu server, not my mac though... no GUI, since it's a bare ffmpeg install, but for you who wants to do heavy transcoding, i say this is the right one up to the task, well at least for me :) , as i'm currently on a project developing a website which require video transcoding capability.

Posted by: Awidarto | July 29, 2007 07:13 AM

Is there a good Linux GUI for ffmpeg around? Command line is just fine for heavy use but something like SUPER for Linux would be great.

Posted by: Jukka Eklund | July 29, 2007 08:16 PM

informative blog

Posted by: Shital Jethva | August 3, 2007 12:57 PM

Hi there!
it didn't work for me. I get an error with my s60 in smartmovie complaining about 'bad AVI'. It worked out with this script and using mencoder instead. In case someone find this useful:

#!/bin/sh
#mencoder -of avi -ovc xvid -xvidencopts bitrate=500:interlacing -afm ffmpeg -af resample=16000,channels=1 -oac mp3lame -lameopts cbr:br=64:mode=3 -noskip -vop scale=208:176 flv/tAsOfqCy4A0.flv -o prueba.avi

if [ -z "$1" ]; then
echo "Usage: $0 list_of_flv_files"
exit 1
fi

# video encoding bit rate
V_BITRATE=50
while [ "$1" ]; do
mencoder -of avi -ovc xvid -xvidencopts bitrate=$V_BITRATE:interlacing -afm ffmpeg -af resample=16000,channels=1 -oac mp3lame -lameopts cbr:br=64:mode=3 -noskip -vop scale=208:176 "$1" -o "`basename $1 .flv`.avi"
shift
done


Save it as flv2avi.sh and
$chmod 755 flv2avi.sh

Change bitrate if you feel like
Theres a similar script I found somewhere.. but it didn't work for me.. thats why i made this one

Posted by: Ivan | August 20, 2007 07:05 PM

MP3 To Ringtone Gold is a ringtone converter. It can be used to convert the popular compressed audio formats (.mp3,.wma,.wav,.ogg) to ringtone format(.mmf,.amr,.mp3,.wav, .qcp) and send them to your cell phone.
download site: http://www.qweas.com/download/audio_mp3/audio_converters/mp3_to_ringtone_gold.htm

Posted by: freda | August 28, 2007 05:10 AM

MP3 To Ringtone Gold is a ringtone converter. It can be used to convert the popular compressed audio formats (.mp3,.wma,.wav,.ogg) to ringtone format(.mmf,.amr,.mp3,.wav, .qcp) and send them to your cell phone.
download site: http://www.qweas.com/download/audio_mp3/audio_converters/mp3_to_ringtone_gold.htm

Posted by: freda | August 28, 2007 05:14 AM

A great side-effect of installing pspvc is that it installs a version of ffmpeg that is able to convert video for the PS3 as well. Normally, this is a really painful and complicated process. Installing pspvc does this for you. One catch, though, is that the install scripts for pspvc are a little screwy and end up installing ffmpeg in a really weird path (they probably meant for it to install in /usr/share or...):

Posted by: Offshore software Development | September 17, 2007 08:17 AM

Nice Article.

Posted by: Easyrules | October 18, 2007 02:43 PM

I mostly used MP4 Music or Iphone ringtones in the mobile. But the ffmpeg is new for me and i will check it out later.

Posted by: chankya | October 23, 2007 11:52 AM

My script seems to convert .avi, .wmv, mpeg to .flv but doesn't convert .mp4 to .flv.

It produces a .flv file that is 0kb (a file with nothing in it) in the Destination directory.

Any idea where i'm going wrong?

ffmpeg -i $source -ab 56k -ar 22050 -b 500k -r 15 -acodec libmp3lame -sameq -f flv $destination

Posted by: Ipod music | December 10, 2007 07:47 AM

My script seems to convert .avi, .wmv, mpeg to .flv but doesn't convert .mp4 to .flv.

It produces a .flv file that is 0kb (a file with nothing in it) in the Destination directory.

Any idea where i'm going wrong?

ffmpeg -i $source -ab 56k -ar 22050 -b 500k -r 15 -acodec libmp3lame -sameq -f flv $destination

Posted by: Ipod music | December 10, 2007 07:49 AM

Great guys informative blog

Posted by: Offshore software development | June 16, 2008 11:38 AM


Post a comment







«Back to previous page