VideoEncoding

General Information

The native display format of the Nokia 770 is 800x480 pixels. Full display area can be used in videoplayer by pressing the fullscreen button. When windowed, video is played at 600x360 pixels. Both give a 15:9 aspect ratio, not quite the 16:9 that is broadcasting standard, but close enough to look good.

Video Player limitations

The media player has some limitations due to the internal hardware:

  • it can only decode videos where horizontal and vertical dimensions are multiples of 16.
  • it cannot decode videos with high bitrates and/or high frame sizes. The limits are at about 800 kbps or 352x288 (to be confirmed - please add your experience)
  • it cannot decode both a high frame rate and a high frame size so if you want to keep the natural frame rate of your video (25 or 30 fps) you have to keep the frame size below 288x160
  • audio must be at 44.1kHz or lower
  • external subtitles cannot be read so they have to be written inside the video frames
  • DivXs need a FOURCC of "DIVX" rather than "DX50"

To encode video that will scale nicely to the screen aspect ratio, you can use either 240x144 (slightly larger than QCIF) or 352x208 (slightly smaller than CIF). Of course if your source video is in a 4:3 aspect ratio, then you should stick with CIF (352x288) or QCIF (176x144). The video player will add black bands when needed.

Frame rate should be adjusted according to frame size because 770 is somewhat limited in cpu cycles and memory bandwidth. For QCIF 24fps is attainable, for CIF keep it below 15fps, for the larger 16:9 aspect videos drop a few fps. Just keep in mind that the more complex the action is in the video, the more cycles it takes to decode. Some folks have noted that sacrificing resolution to maintain high frame rates results in more watchable results, your mileage may vary. If the natural frame rate of your video works, you are probably better off keeping it.

As for the audio subsystem, mp3 at 128 kbps just works fine. You can reduce the bitrate if you want to limit the file size and if you plan to play the file with the internal speaker only.

Alternative video players

MPlayer can be used to overcome some of the default player limitations and play full framerate video. Also it supports external subtitles.

Online converters

http://www.bleb.org/services/vidconvert/ will allow file uploads and URLs to be specified resulting in a Nokia 770-compatible DivX which can be streamed or downloaded to your device.

Software converters

Media Converter

http://www.helsinki.fi/~konttori/mediaconverter0-4.jpg

Media Converter eases the process of converting videos to Nokia 770 mpeg4 format. It also supports two-pass coding that produces better quality videos. Screenshot's quite old. New one much better. Supports dragn drop of files.

Note: Sun Java 1.4 or later needed. Linux version needs mencoder installed.

MediaCoder

http://mediacoder.sourceforge.net/

Media Coder can be used to directly convert VOBs (DVD files) into AVI's and provides several encoder to convert them into playable formats for mplayer. It is a great software for video editing and format conversion. The best thing about this is that it allows the end-users to select the audio tracks for the video to be encoded, unlike Kontori Media Converter which use the default audio track . You can also do many other things like set different screen sizes and bit rates. It works for all devices as well.

encode770

http://www.cs.tut.fi/~ranki/projects/encode770/

A script based on some code from here

770-encode

http://www.bleb.org/software/770/#encode

Another script based on mencoder and Perl. Designed for simplicity it aims to guarantee not to produce unplayable video using a "presets" system.

It can take anything mplayer can use as an input (e.g. DVDs, RealVideo streams, MPEG files, AVIs) and convert them into 770-compatible DivX:

770-encode <del>preset=best </del>two-pass dvd://1 my-dvd.avi

Tested on Mac OS X, Linux and Windows.

Handbrake

"HandBrake is a GPL'd multiplatform, multithreaded DVD to MPEG-4 ripper/converter. HandBrake was originally available on the BeOS, but now has been ported over to MacOS X and to GNU/Linux." -- http://handbrake.m0k.org/

Handbrake will allow a direct rip from a device to the format that will play on the 770. This first screenshot shows example settings (based on information found in this wiki) that are known to work. In order to change the size, you must click on the "Picture settings..." button at the bottom. This will bring up the a dialog box, where you'll need to specify the size (288x160 is what I used).

http://homepage.mac.com/e4jet/screen/handbrake-770-format1.gif

Tested on Mac OS X

Creating Streamable Video Yourself

As the 770 supports RealVideoStreams, you can use HelixProducer to create them from your own inputs.

Manual conversion instructions

Mencoder

The tool I use to encode video is mencoder that comes with mplayer on Linux. Always start with the cleanest video you can, and make sure it has good A/V sync before you start by watching it on a PC. Make sure the original has a frame rate greater than or equal to the one you are trying to generate. Here is an example mencoder shell script:

#!/bin/bash

FILE="My video.xvid-lol.avi"     # source file
SUB="My video.xvid-lol.FR.srt"   # subtitles
OUT=MyVideo.avi                  # target file
RES=288:160                      # resolution
ABR=96                           # audio bitrate
VBR=500                          # video bitrate

rm divx2pass.log 2>/dev/null

nice -n 19 \
mencoder "$FILE" \
    - o "$OUT" \
    - sub "$SUB" \
    - subfont-text-scale 4 -subcp latin1 \
    - oac lavc -lavcopts acodec=mp3:abitrate=$ABR \
    - ovc lavc -lavcopts vcodec=mpeg4:autoaspect:vbitrate=$VBR:vpass=1:turbo \
    - vf scale=$RES \
    - ffourcc DIVX \
    - idx


nice -n 19 \
mencoder "$FILE" \
    - o "$OUT" \
    - sub "$SUB" \
    - subfont-text-scale 4 -subcp latin1 \
    - oac lavc -lavcopts acodec=mp3:abitrate=$ABR \
    - ovc lavc -lavcopts vcodec=mpeg4:autoaspect:vbitrate=$VBR:vpass=2 \
    - vf scale=$RES \
    - ffourcc DIVX \
    - idx

]

Here's another version that is interactive:

#!/bin/bash
#
# n770encode.sh
#
# Usage: n770encode.sh inputfile
#

FILE=$1
OUT=`echo -n "$FILE" | sed 's/\.[a-zA-Z0-9]\+$/-n770.avi/'`
ABR=96
VBR=350
RES='err'

echo "Processing input file $FILE..."
echo
echo "Aspect ratio?"
echo "(1) 4:3"
echo "(2) 16:9"
echo -n "Select [2]: "
read aspect
if [ "$aspect" = "1" ]; then
  RES='176:144'
else
  RES='240:144'
fi

echo -n "Video bitrate? [$VBR]: "
read vbr_in
if [ "$vbr_in" != "" ]; then
  VBR=$vbr_in
fi

echo -n "Audio bitrate? [$ABR]: "
read abr_in
if [ "$abr_in" != "" ]; then
  ABR=$abr_in
fi

rm -f divx2pass.log 2>/dev/null

nice -n 19 \
mencoder "$FILE" \
    - o "$OUT" \
    - oac mp3lame -lameopts abr:br=$ABR \
    - ovc lavc -lavcopts vcodec=mpeg4:autoaspect:vbitrate=$VBR:vpass=1:turbo \
    - vf scale=$RES \
    - ffourcc DIVX \
    - idx

nice -n 19 \
mencoder "$FILE" \
    - o "$OUT" \
    - oac mp3lame -lameopts abr:br=$ABR \
    - ovc lavc -lavcopts vcodec=mpeg4:autoaspect:vbitrate=$VBR:vpass=2 \
    - vf scale=$RES \
    - ffourcc DIVX \
    - idx

You can also try running mencoder directly and playing with the options. Be careful about forcing the output frame rate, however. I didn't get any good result with the below commands. Instead, I got A/V desync and bad effects due do frame rate changes, so I now use some variation of the above shell scripts.

mencoder infile.avi -oac mp3lame -ovc lavc -lavcopts vcodec=mpeg4 -vf scale=352:208 -ffourcc DIVX -ofps 15 -o outfile.avi

This will generate a 15fps 352x208 avi file.

The following mencoder command line will make smaller videos:

mencoder infile.avi -oac mp3lame -ovc lavc -lavcopts vcodec=mpeg4:mbd=1:vbitrate=300 -vf scale=352:208 -ffourcc DIVX -ofps 15 -o outfile.avi

To make even smaller, you can drop down the quality of audio to 64 kbit/s (for 300 kbit video stream, converting audio to 64 kbit versus 128 kbit yields a total save of approx 20%. Notice that for lower bitrate movies percentage is considerably higher):

mencoder infile.avi -oac mp3lame -lameopts abr:br=64 -ovc lavc -lavcopts vcodec=mpeg4:mbd=1:vbitrate=300 -vf scale=352:208 -ffourcc DIVX -ofps 15 -o outfile.avi

The differences are the block detection method (mbd=1) and a capped bitrate see man mencoder for more options

ffmpeg

It is possible to transcode a video with ffmpeg. But the video will have a corrupted fourcc header. This can be corrected with the tool avifix from transcode or by using -vtag DIVX in ffmpeg command line:

ffmpeg -i infile -vcodec mpeg4 -acodec mp3 -s 176:144 -b 200 -pass 1 outfile.avi
ffmpeg -i infile -vcodec mpeg4 -acodec mp3 -s 176:144 -b 200 -pass 2 outfile.avi
avifix -i outfile.avi -F "divx"

Or directly (without avifix):

ffmpeg -i infile -vcodec mpeg4 -acodec mp3 -vtag DIVX -s 176:144 -b 200 -pass 1 outfile.avi
ffmpeg -i infile -vcodec mpeg4 -acodec mp3 -vtag DIVX -s 176:144 -b 200 -pass 2 outfile.avi

transcode

I just converted a DVD using transcode using the following command line:

transcode -i /dev/dvd \
          - x dvd \
          - T 1,1-16 \
          - a 0 
          - j 48,0,48,0 \
          - Z 240x160 \
          - y xvid \
          - V -w 300 \
          - N 0x55 \
          - b 48 \
          - o output.avi

This transcodes chapters 1 to 16 of title 1. The DVD has 720x576, but uses only 720x480, so I clipped off the remaining 96 black pixels with the -j option. Output size is 240x160. Video bitrate is 300kbps, audio is 48kbps. The "xvid" codec (a symlink to xvid2 on my system) gives very good results with the default settings. Do not use "mpeg4", it needs too much processor power for decoding which causes loads of artefacts when playing on the 770, even if it looks good on a PC.

I used the transcode package with Debian unstable.

afterwards, I fixed the FOURCC with

avifix -i output.avi -F DIVX

The resulting AVI file has 114 MByte for 45 minutes/25fps. Things can certainly be improved by tuning xvid options using a ./xvid2.cfg, but I didn't try that yet.

Here is another example, where the DVD has 720x576 fully used for 4:3 content. I chose 256x192 as output size (4x64, 3x64). This time I used the xvid4 codec. Note that you must not use B-frames, the 770 doesn't seem to be able to handle them. You can turn them off by setting max_bframes=0 in your xvid4.cfg, you can easily do this with the xvid4conf tool. After you did this, the following command line will do the rest:

transcode -i /dev/dvd \
          - x dvd \
          - T 1,-1 \
          - a 0 
          - Z 256x192 \
          - y xvid4 \
          - V -w 300 \
          - N 0x55 \
          - b 48 \
          - o output.avi

The -T 1,-1 option will convert the whole title 1 (all chapters). You can try a lower video bitrate by adjusting the -w parameter (300kbps in this example). Don't forget to fix the FOURCC with the avifix command (as above)! The quality is very good, and it works fine with 25fps.

Additional informations regarding transcode and IT 2006 beta :

I suggest using the following command-line :

transcode -i /dev/dvd \
          - x dvd \
          - T 1,-1 \
          - a 0 
          - Z 352x208 \
          - -keep_asr \
          - y ffmpeg \
          - F mpeg4 \
          - w 300 \
          - N 0x55 \
          - b 48 \
          - R 1 \
          - o output.avi

and 
transcode -i /dev/dvd \
          - x dvd \
          - T 1,-1 \
          - a 0 
          - Z 352x208 \
          - -keep_asr \
          - y ffmpeg \
          - F mpeg4 \
          - w 300 \
          - N 0x55 \
          - b 48 \
          - R 2 \
          - o output.avi

using ffmpeg, there is no need to fix FOURCC. -R x is used to do two-pass encoding. --keep_asr will resize source video to fit in the specified target resolution, no need to worry about cropping or adding black borders if source isn't using the same aspect ratio (DVD often uses 1.77 anamorphic format ), transcode will take care of it. The only choice to do is target resolution : 320x208 or 240x144 for 16:9 source, 352x288 or 176x144 for 4:3 source.