Since I have just gotten an IPhone 3G it is finally necessary for me to do a how to on encoding videos that you can view on your IPod or IPhone from movies on your PC or DVD’s in your collection.

First note that there are many tools on different platforms to accomplish this task. Personally I do all of my encoding work from a linux command line as it gives me finer grain control over the configuration and is easier on the resources as video encoding is highly CPU intensive.

That being said, the tools that I use for this tutorial are x-platform, meaning they are available on Linux, Windows, and Mac. i will be concentrating on the Linux command line version of Handbrake as the GUI tools are pretty self explanitory.

Software:

HandBrake is a tool to encode different file formats. There is also a graphical version for Mac and Windows but I prefer the CLI version for Linux.

The binary packages for linux apparently only exist for Ubuntu so if you use a distro such as Slackware like myself, it is necessary to build the program from source.

Install:

The handbrake build uses Jam which is a make like utility. On Fedora you can find this in the fedora yum repos. For Slackware I was able to find it in slacky repo under development, need to add this repo to your slapt-getrc file:(I use slapt-get for package management, if you dont just download and install the tgz file manually)

http://repository.slacky.eu/slackware-12.1/

$>slapt-get –install jam

You also need glibc-2.7 or higher

I was able to find it a slackware packge here:

http://packages.slackware.it/package.php?q=current/glibc-2.7-i486-17

you can upgrade using upgradepkg command:

$>upgradepkg glibc-2.7-i486-17.tgz

this will upgrade your current version of glibc to 2.7

Now install Handbrake

Download handbrake source from:

http://handbrake.fr/rotation.php?file=HandBrake-0.9.3.tar.gz

unpack

$>tar zxvf HandBrake-0.9.3.tar.gz

Build

$>make

(use j switch for multiprocessor machines IE:make -j4 if you have 2 processors)

Now you should end up with a file called HandBrakeCLI in the build directory.

You can move this file to somewhere in your path so you can execute it from anywhere.

now type “HandbrakeCLI –help” and press enter, and you should see the help output of handbrake.

your are successfully installed at this point

Create IPhone Videos:

Now that we have HandBrake installed, it is time to put it to work. The –help command provides a lot of information on how to use the application so if you are comfortable with command line and have experience with linux man pages then you should be right at home. For others are are some steps to encode video:

HandBrakeCLI –help list all of the available options, their meanings and how to use them. At first it might look confusing but don’t let it slow you down, just ignore all the foolishness. You’ll start to understand how to decipher all that helpful information after you’ve looked at how the commands are setup.

You might not have noticed it if your terminal window is too small, but at the very top of the built-in help it says Syntax: HandBrakeCLI [options] -i <device> -o <file>. This line tells you exactly how to construct your HandBrake command. For example, HandBrakeCLI –help, the –help replaces the [options] in the syntax, however, –help is a special option so we don’t specify any -i input device or -o output file name.

Now let’s move on to something that actually uses a DVD. Since chances are that we’ll all be using a differentDVD to test with I’m going to use MY_DVD to represent a generic path, your specific path will be different. You want to use the mount point of the drive.(like /media/dvd or so). Go ahead and insert a DVD, when you see the DVD icon on your desktop you’re ready to go.

If you need to encode a DVD that is already ripped to your HDD then MY_DVD should be the path to your VIDEO_TS folder. Also if you are trying to encode an .avi file or any other such file then you would point to that file.

now at the command line type:

$>HandBrakeCLI –title 0 –input /Volumes/MY_DVD

or
if encoding a ripped dvd

$>HandBrakeCLI –title 0 –input /home/dtek/transformers/VIDEO_TS

or
if encoding a single file

$>HandBrakeCLI –title 0 –input /home/dtek/ironman/ironman-720p.avi

In the previous command –title 0 instructs HandBrakeCLI to scan the DVD and display all kinds of technical information in the Terminal window. This information can be invaluable if you are unsure what exactly is on the DVD. For instance, you may want to add subtitles but are unsure which track contains the English subtitles you want, so HandBrakeCLI –title 0 –input /Volumes/MY_DVD will show you the full list of available subtitles and which track contains which language. It will look something like:

+ subtitle tracks:

+ 1, English (iso639-2: eng)

+ 2, Espanol (iso639-2: spa)

+ 3, Francais (iso639-2: fre)

So, now you know the English subtitles are in subtitle track 1 and you’re ready for your first encode.

$>HandBrakeCLI –subtitle 1 –input /Volumes/MY_DVD –output ~/Desktop/My_DVD.m4v

And that’s all there is to it. You can see in the [options] section we only have –subtitle 3 this time. For every option that you don’t set HandBrakeCLI automatically inserts the “classic” default value. So the above command is equal to inserting a DVD, picking French subtitles, the Classic preset and clicking Start in theGUI.

If you now run

$>HandBrakeCLI –help

and look in the ### Picture Settings sections you’ll see -s, –subtitle <number> and it will make perfect sense how that bit from the built-in help translates into direct use; you’ll also now know that our previous encoding command could have been more succinctly written as:

$>HandBrakeCLI -s 1 -i /Volumes/MY_DVD -o ~/Desktop/My_DVD.m4v

I’ll continue using the long commands for clarity but you can feel free to start substituting the short commands as you learn them

Now lets try to change the encoder to xvid:

$>HandBrakeCLI –subtitle 1 –encoder xvid –input /Volumes/MY_DVD –output ~/Desktop/My_DVD.m4v

and now try to guess what the command would look like for using the x264 encoder instead of xvid. Of course, you guessed:

$>./HandBrakeCLI –subtitle 1 –encoder x264 –input /Volumes/MY_DVD –output ~/Desktop/My_DVD.m4v

Have another look at the built-in help, this time under the ### Video Options at the encoder settings and again you’ll now understand how that help info translates into usage. You can now probably peruse the help and guess correctly how to use nearly, if not all, the commands; and just to prove it to yourself try constructing commands that will:

use the the encoder of your choice but constrain the picture to 640×480

use the x264 video encoder, passthrough audio and deinterlacing

If you came with commands like:

$>HandBrakeCLI –encoder xvid –width 640 –height 480 –input /Volumes/MY_DVD –output ~/Desktop/My_DVD.m4v

and

$>HandBrakeCLI –encoder x264 –aencoder ac3 –deinterlace –input /Volumes/MY_DVD –output ~/Desktop/My_DVD.m4v

then you’re probably ready for something a little less basic. Check this command out

$>HandBrakeCLI –preset “Deux Six Quatre” –input /Volumes/MY_DVD –output ~/Desktop/MY_DVD

As you can probably guess it uses the Deux Six Quatre preset just like the GUI.

Now here is a real life example where I encode a full IronMan dvd that I have previously ripped to my hard drive:

dtek@tek-eserv1:~/ironman$ HandBrakeCLI -C 4 –preset=”iPhone & iPod Touch” -Y 320 -2 -T -r 23.976 –input /eblock/ironman/Ironman720p.avi –output /fblock/rip/ironman.m4v

I explicitly set the number of processors to use with “-C 4″, the default is for Handbrake to auto-detect this so it is really not necessary.

Also ss you can tell I have used the preset settings for iphone with “iPhone & iPod Touch” preset. This presets sets the maxWidth to 480 as we expect for Iphone but leaves the maxHeight blank. I set the maxHeight to 320 with “-Y 320″ option. It also sets a number of other defaults for the IPhone as well, You can get a list of all presets by doing:

HandBrakeCLI –preset-list

The options “-2 -T” tell the application to use 2 pass encoding which greatly increases the video output quality but makes the process take twice as long(think multiple hours on a single processor machine). The -T option says to use turbo mode of the first pass which can speed the process somewhat.

Since the source of this dvd was pal I use ” -r 23.976” to change the frame rate to the NTSC setting of 23.79fps.

Thats pretty much it. You should have enough information to go out and start encoding!

Tags Tags: , , , , ,
Categories: IPhone, linux
Posted By: DteK
Last Edit: 07 Oct 2009 @ 09 02 PM

E-mailPermalinkComments (48)
\/ More Options ...
Change Theme...
  • Role »
  • Posts »
  • Comments »
Change Theme...
  • VoidVoid (Default)
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LiteLightweight
  • No Child Pages...