- Have a Blackberry
- Have a computer running Linux (preferably a recent suse-based distro)
- Have a DVD player in that computer
- Need to make mini copies of individual chapters of any given DVD
…then this post is for you. Of course, I know this post will be of interest to about 5 people in the world besides me, but I’m going to do it anyway…. 😉
I occasionally have a need to entertain a small child with some favorite children’s videos, featuring a particular small blue cartoon dog from a now-defunct children’s show. I don’t carry around a DVD player with me everywhere, but I *do* carry my Blackberry everywhere. So I created a script that will loop through a DVD and make individual AVI movies for each chapter on the DVD, so I can transfer them to my Blackberry and have them available any time I need them. I want to share that script with you.
(Please note that I’ve been doing this on Opensuse 11.3 in the past, and now 11.4; so if you have a different version or distro, make sure to modify anything necessary to suit.)
First, some pre-requisites…
You may or may not have DVD region issues with your DVD player and discs, depending upon where you are located. I install and use a handy little
regionset tool like this:
rpm -Uvh http://linvdr.org/download/regionset/regionset-0.2-de.rpm
…then run the
regionset command and set your zone appropriately. Just know that the entire dialog is in German, and “j”=ja/yes and “n”=nine/no.
You need to have the
mencoder utility installed. This means you have to have the
MPlayer package installed, and you probably need the Packman software repository set up. It’s hard for me to offer advice on how to go about this, because there are bunch of ways. Let me just give you the link to the “Restricted Formats” setup page:
…and assume you have done the work necessary to have the
I use the
lsdvd utility to be able to know how many “chapters” there are for each DVD. Unfortunately, some DVDs have tiny little (one or two second) useless “chapters” that end up getting converted in this process, that you just delete later. But you still need to know how many chapters that the DVD itself shows are there. This is where the
lsdvd utility comes in handy. You just install it with the following command:
zypper in lsdvd
…and run it with a simple
lsdvd command. The results seem to be quite different from DVD to DVD, so I apparently cannot automate the parsing of the result for the script; and human parsing of the results is apparently mandatory. Oh well, one human step is not bad….
The Mencoder Loop Script
Now that you’ve done all the leg work, let’s have some fun. Save the following script, *read it over*, do a
chmod +x against it, and run it…
#!/bin/bash # Dont touch these variables DATE=`date +%Y%m%d%H%M%S` x=0 # Get some input lsdvd echo "Look at the lsdvd output above to figure out the chapter count." echo "How many chapters are there?" read CHAPTERS echo "Give me a short name (no spaces) to reference this dvd by..." read SHORTNAME # Build the working folder WORKDIR="/tmp/dvd.$SHORTNAME.$DATE" mkdir "$WORKDIR" # Now do the work while [ $x -lt $CHAPTERS ] do let x=x+1 echo "Now dumping Chapter $x..." mencoder dvd://1 -chapter $x-$x -vf crop=704:464:8:6,scale=320:240 -ovc xvid -xvidencopts bvhq=1:chroma_opt:quant_type=mpeg:bitrate=658:pass=2 -alang en -oac mp3lame -lameopts br=96:cbr:vol=1 -o "/$WORKDIR/$SHORTNAME-chapter$x-phone.avi" sleep 1 done # All done! eject cdrom
So to summarize the script: It asks you how many chapters (to determine how many times to loop) and for a logical name (for naming the work folder and filenames); it builds the work folder; then it loops through all the chapters on the DVD, encoding them in AVI format in a small size that should be perfect for BlackBerries.
Of course, all the magic is really in the
mencoder line, and there are a lot of options I’ve settled on over time… like small Blackberry screen size, and volume at 1 or 2 (depending on what I’m converting), etc.; I strongly encourage you to jump in and read the docs to be sure you tune it to taste.
And that should do it… Happy viewing!