How to encode h264 video files for Nokia Series 60 standalone playback

Posted on September 23, 2008  by Mikko Ohtamaa
Filed Under linux, mobile, series 60, ubuntu

Bored with Spiderman 3 which came with your Nokia N95 8 GB? This guide shortly tells how to get movies into your N95 on Ubuntu Linux using ffmpeg video encoder. The aim is to encode video suitable for playback from Nokia N-series (N95, N78, others) mobile phone memory card. We use h264 + AAC codecs which provides the best quality/compression rate for Nokia phones currently.

Ubuntu does not distribute proprietary codes. First thing you need to do is to rebuild ffmpeg.  Since Ubuntu 8.04 Hardy Heron ships with ffmpeg from 2007, which is aeons old in video codec years, you need to build libx264 and ffmpeg from SVN sources. Here are detailed, valid, instructions. Note that FFMPEG trunk is not currently stable (September 2008), so you need to use revision 15261 which needs this little patch. Indeed, this is a very difficult month to start your career in the dark world of video encoders.

To make it legal and support open source codec development,  please pay for your codecs.

Then we use this guide by Robert Swain. We have a tiny sub 2,4″ screen, we do not care about the quality and do one pass encoding. By empirical research, I have found that the following MPEG-4 profile parameters are compatible with N95 8 GB and provide the optimal result. You can vary video and audio bitrate depending on your taste.

Here is a script which recursivelu encodes all detected video files suitable for mobile format:

#!/bin/sh
#
# Optimal movie encoding for Nokia N-series mobile phones
#
# Copyright 2008 Red Innovation Ltd.
#
# Say hi if you find this useful.
# We do some professional mobile video publishing, so if you
# need a helping hand please call us.
#
# Usage: Run encode.sh in any folder and all video files are recursively converted to mobile phone suitable format
#
# Note: We expect all the source material be in 16:9 aspect ration
#
# Also see http://www.nseries.com/index.html#l=support,search,faq,general,video%20encoding,53848
#

VIDEO_BITRATE=300k

AUDIO_BITRATE=72k

# Assume locally build ffmpeg + x264 in /usr/local/bin
# http://ubuntuforums.org/showthread.php?t=786095
export LD_LIBRARY_PATH=/usr/local/lib

# Search all source AVI, MPG and WMV video files
# Place all encoded files to the same folder with the source, with added .mp4 extension
find . -iname "*.avi" -or -iname "*.wmv" -or -iname "*.mpg" | while read src ; do
        srcfile=`basename "$src"`
	srcfolder=`dirname "$src"`
	dstfile="$srcfolder"/"$srcfile".mp4

	# The magical string!
	# Size and cropping is for 16:9 source material, so that 320:240 display will have black bars.
	# Fex pixels off... note that h264 sizes must be multiplies of 16, use 256x144 for streaming
	# N95 RealMedia player does not seem to respect MPEG-4 embedded aspect ration info.
	/usr/local/bin/ffmpeg -y -i "$srcfile" -acodec libfaac -ab $AUDIO_BITRATE -s 320x176 -aspect 16:9 -vcodec libx264 -b $VIDEO_BITRATE -qcomp 0.6 -qmin 16 -qmax 51 -qdiff 4 -flags +loop -cmp +chroma -subq 7 -refs 6 -g 250 -keyint_min 25 -rc_eq 'blurCplx^(1-qComp)' -sc_threshold 40 -me_range 12 -i_qfactor 0.71 -directpred 3 "$dstfile"

done

Share This

 

Other posts by Mikko Ohtamaa

 

Comments

3 Responses to “How to encode h264 video files for Nokia Series 60 standalone playback”

  1. Per Blomqvist on October 7th, 2008 2:53 am
    Gravatar

    Wow, it worked!
    (I didnt reinstall ffmpeg.. Im debian testing user)

    One thing though, there was no preview-image (in the folder of “My Videos”)?

    I have tried to encoding mp4-files for my N95, for a loong time now…
    (here are the previous successful line:

    mencoder -of lavf -lavfopts format=mp4 -oac lavc -ovc lavc -lavcopts aglobal=1:vglobal=1:acodec=libfaac:abitrate=128:vcodec=mpeg4:keyint=25:vpass=1 -ofps 25 -af lavcresample=44100 -vf yadif,scale,crop=384,harddup -zoom -xy 512 INPUTFILE.avi -o output.mp4 -idx

    (This is an modification of
    http://notes.xiaoka.com/2008/03/29/encode-mp4-files-for-nokia-n95-with-mencoder/
    And it encode in mpeg4 video-format)

    (Here are another older post, that did something also:
    http://wiki.dumbot.net/Video_processing
    It produced something.. But I didnt get the idee of separating sound and video, and later boxing)

    An alternative to all these hassling is to install a DivX-payer on the phone: http://www.divx.com/mobile/ (it works good)

    I used to encode with mplayers mencoder, ffmpeg is something obscure cuttingedge (I dont know how many days your example will work).

    Im looking for a way to postprocessing recorded TV shows. Too a format that can be viewed in my N95, and also streamed on the web in a flashplayer. This demand mp4 (or possible old .flv). And I find the video codex h264 the best.

    I cant grasp if x264 and h264 is the same thing, or twat.

    What was that about paying for codex about???

    (strange, allot of fuzz.. Feels good when things working, for once

    THX

     
  2. Per Blomqvist on October 17th, 2008 9:07 pm
    Gravatar

    Still strange, previous message awaiting moderation.

    I see options in your ffmpeg command, that doesnt have any reference (mystery).

    “-flags +loop” “-cmp +chroma” .. ???
    Nowhere tobe found in any documentations.

    ffmpeg have a documentation package in Debian. BUT, ist doxygen of its source. Uncompromisable!

     
  3. R E Broadley on March 2nd, 2009 6:24 pm
    Gravatar

    How strange. ffmpeg works fine with vcodec of xvid at a resolution of 640×480, but for x364 the resolution seems to need to drop before it works, so overall, I’m not sure if the quality is better compared to xvid… I’ll have a fiddle around and try to get to the bottom of this…

    thanks for the post!

     

Leave a Reply




Copyright © Red Innovation Ltd. 2009 All Rights Reserved. | Log in | XHTML
Close
E-mail It