• Business posts
  • Technology posts
  • Company site
  • SubscribeRSS

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
Tags: aac, build, dvd, encoding, ffmpeg, h264, libfaac, libx264, linux, mobile, movie, n95, series 60, tutorial, ubuntu, video, x264

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
 

Other posts by Mikko Ohtamaa

 

Comments

2 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!

     

Leave a Reply




  • About

    Twinapex Blog is the voice of mobile and Internet experts. We tell tales about our exciting life in the world where communication methods convergence and you can access whatever information you wish, wherever, on whichever device you want.

    If you find us interesting and talented and you are looking for developers, please contact us and we might just be able to help you.

    Creative Commons License
    This work is licensed under a Creative Commons Attribution 3.0 Unported License.

  • Recently Written

  • PyDev, Python and system default Unicode encoding problem
  • Creating a drag’n’drop basket with jQueryUI
  • Mobile browser wars: Nokia microB vs. Firefox Fennec
  • Profiling PostgreSQL database
  • It will be damn big, and damn fast…
  • Black Friday was not sad for mobile commerce
  • Nokia N900, sports tracking and geotagging
  • PhoneGap ported on N900 (Maemo)
  • Do you really think 160 chars tells the story?
  • Installing Python Imaging Library (PIL) under virtualenv or buildout
  • Tags

  • aggregator analytics android api buildout c++ cms comic debug debugging developer django documentation eclipse extjs failure html iphone javascript jquery language linux mobile multilingual nokia php plone Plone (old) pys60 python release rss s60 seo series 60 setuptools sql subclipse symbian ubuntu usability virtualenv web web development zope
  • Monthly Archives

  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • February 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
 
© Twinapex Oy 2010 Log in