e42.uk Circle Device

 

Quick Reference

BlackBerry h.264 Encoding with FFMPEG

The BlackBerry (Bold 9900 at least) makes use of the same profile as the iPod/iPhone when playing back h.264 encoded video. For those who care (I do so others might) that is baseline, level 3.0. The results of the script below is also compatible with firefox and other browsers. So, using ffmpeg you can encode a video for BlackBerry like this:

infile="$1"
outfile="$2"
options="-s 640x360 -vcodec libx264 -b:v 512k -flags +loop+mv4 -cmp 256 \
 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 \
 -me_method hex -subq 7 -trellis 1 -refs 5 -bf 0 \
 -coder 0 -me_range 16 -pix_fmt yuv420p \
 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 \
 -qmax 51 -qdiff 4"

ffmpeg -y -i "$infile" -an -pass 1 -threads 2 $options "$outfile"

ffmpeg -y -i "$infile" -ac 2 \
 -acodec libmp3lame -ar 44100 -b:a 128k -pass 2 \
 -af "pan=stereo|c0<FL+BL+FC|c1<FR+BR+FC" \
 -threads 2 $options "$outfile"

If you are interested in the older version:

infile="inputfile.avi"
outfile="video.mp4"
options="-s 640x360 -vcodec libx264 -b 512k -flags +loop+mv4 -cmp 256 \
 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 \
 -me_method hex -subq 7 -trellis 1 -refs 5 -bf 0 \
 -flags2 +mixed_refs -coder 0 -me_range 16 \
 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10\
 -qmax 51 -qdiff 4"

ffmpeg -y -i "$infile" -an -pass 1 -threads 2 $options "$outfile"

ffmpeg -y -i "$infile" -acodec libmp3lame -ar 44100 -ab 64k -pass 2 \
 -threads 2 $options "$outfile"

And that is it, simple when you know how.

I should not forget to mention that I got this from http://h264.code-shop.com/trac/wiki/Encoding the only thing I added was the scaling component -s 640x360 which happens to be a good setting for widescreen on BlackBerry.

Other interesting links for encoding with h.264: ffmpeg and mencoder | and here | one more. One final note is that ffmpeg (the utility programme) is no longer actively developed and you would be wise to look into avconv

avconv is just some kind of fork and ffmpeg is still maintained, please accept my apologies for this I read it when installing ffmpeg on Debian.

Script updated to support newer ffmpeg: 2.2.7.

References

Quick Links: Techie Stuff | General | Personal | Quick Reference