Old Blogs

Old blogs

Video transcoding using ffmpeg

Video - November 29th, 2006 - Written by Oren Levine

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:
- 208×176 (normal, or legacy resolution)
- 416×352 (double resolution)
- 320×240 (QVGA)
- 208×208 (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:
- 208×176 (normal, or legacy resolution): 208×112
- 416×352 (double resolution): 352×192
- 320×240 (QVGA): 320×176

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 320×176 frame size):

ffmpeg -i movie.avi -f mp4 -vcodec mpeg4 -b 250000 -r 15 -s 320×176 -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 320×176 : 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 320×176 -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

About the author Oren Levine

I’m Oren Levine and I work in the S60 marketing team, focusing on what S60 offers to software developers and others who are interested in [..]

  • Number of posts: 54

Comments(27)

  1. Jonathan Greene wrote

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

  2. Anonymous wrote

    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.

  3. Skavenger wrote

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

    http://mediacoder.sourceforge.net/

  4. Oren Levine wrote

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

  5. Martin wrote

    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

  6. Alessandro wrote

    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

  7. Jay_cee wrote

    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.

  8. fred wrote

    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

  9. Jukka Eklund wrote

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

  10. fred wrote

    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

  11. Eric wrote

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

  12. Florin wrote

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

  13. David wrote

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

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

  14. Steve wrote

    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?

  15. Nick Burch wrote

    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)

  16. Awidarto wrote

    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.

  17. Jukka Eklund wrote

    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.

  18. Shital Jethva wrote

    informative blog

  19. Ivan wrote

    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

  20. freda wrote

    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

  21. freda wrote

    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

  22. Offshore software Development wrote

    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…):

  23. Easyrules wrote

    Nice Article.

  24. chankya wrote

    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.

  25. Ipod music wrote

    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

  26. Ipod music wrote

    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

  27. chris wrote

    I’m using the basic
    ffmpeg -i movie.avi -f mp4 -vcodec mpeg4 -b 250000 -r 15 -s 320×176 -acodec aac -ar 24000 -ab 64 -ac 2 movie.mp4

    command and completely failing to convert films to play on my E71. If i use it to convert a tv episode it work. both starting files appear to be in identical format but one works and the other doesn’t. Tv ep was house series for finale and underworld evolution and batman begins were the films

Visit new S60 Blogs

You are browsing old S60 blogs. Please note that these sections are not updated any more. Go to the new S60 Blogs to find out the latest news!

New blog categories:

Categories

What is S60?