Blackberry Video Encoding Script

Here is a simple shell script you can use to encode videos for viewing on a BlackBerry. It will run on a Unix, OS X, or Windows with Cygwin installed. You must have mplayer/mencoder installed.

The script will probably work well for any other media player claiming MPEG4 compatibility. Adjust the output resolution, aspect ratio, and bitrates as necessary.

Filename: bbencode.sh

#!/bin/bash
 
# Specify the size of the viewport in the video player.
# For BlackBerry Pearl, use 240 x 180.
SCREEN_WIDTH=240
SCREEN_HEIGHT=180
 
# Specify the video and audio bitrates (kilobits per second).
VIDEO_BITRATE=230
AUDIO_BITRATE=64
 
mencoder -vf expand=:::::4/3,scale=$SCREEN_WIDTH:$SCREEN_HEIGHT "$1" -o "$2" \
   -of avi -ovc lavc -oac mp3lame \
   -lavcopts vcodec=mpeg4:vbitrate=$VIDEO_BITRATE:acodec=mp3:abitrate=$AUDIO_BITRATE
 
# if "-oac mp3lame" doesn't work, try "-oac lavc"

The filters first “expand” the input video to fill a 4:3 frame, letterboxing or pillarboxing as necessary. Then it scales the result down to SCREEN_WIDTH × SCREEN_HEIGHT.

The output is encoded using the MPEG4 video codec and MP3 audio codec, enclosed in an AVI container.

I’ve tested the output with these options on my BlackBerry Pearl 8100 and it gets the job done.

Playback

I highly recommend Mobiola xPlayer for playback. This is payware, but if you do not want live streaming playback, a license is not required.

xPlayer supports fullscreen playback even on the Pearl’s vertically-oriented (240×260) screen, and it supports sending the audio to any possible device (handset, internal loudspeaker, wired headset, bluetooth headset). The scaling algorithm on xPlayer is minimalistic: oversized frames are scaled 50% in each direction repeatedly until the resulting frame size fits on the device’s screen, so you definitely want to preprocess files with the scripts on this page.

Rotating

Since the Blackberry Pearl has a vertically-oriented screen and no players support rotating internally, here is an alternate version of the above script for encoding a file rotated 90° clockwise for the Pearl. I changed the frame size to 256×240 and added the rotate filter.

Filename: bbencode-rotate.sh

#!/bin/bash
 
# Specify the size of the viewport in the video player.
# For BlackBerry Pearl ROTATED, use 256 x 240.
# (mencoder wants dimensions to be a multiple of 16, so we round down to 256.)
SCREEN_WIDTH=256
SCREEN_HEIGHT=240
 
# Specify the video and audio bitrates (kilobits per second).
VIDEO_BITRATE=230
AUDIO_BITRATE=64
 
mencoder -vf expand=:::::16/15,scale=$SCREEN_WIDTH:$SCREEN_HEIGHT,rotate=1 "$1" -o "$2" \
   -of avi -ovc lavc -oac mp3lame \
   -lavcopts vcodec=mpeg4:vbitrate=$VIDEO_BITRATE:acodec=mp3:abitrate=$AUDIO_BITRATE

For 90° counter-clockwise instead of clockwise, change rotate=1 to rotate=3.

Leave a Reply

Please view the Comment Policy before submitting a comment.
 

Your email address will not be published. Required fields are marked *