handbrake cli guide

encoding

this guide makes no attempts to be a definitive guide to "high" quality encoding. Figuring out which quality is "high" quality is an exercise best left to the individual once they've learned the basic commands. So if/when I say something that is different from what you know, go with what you know.

this guide uses /movie as shorthand for "the path to the folder containing the VIDEO_TS folder you want to encode" and /movies/filename for "the path and filename you want to create from the /movie folder"; if you have no idea what sort of values you might need to put in there try this: in Terminal type HandBrakeCLI -i  and drag the DVD icon from your Desktop and drop it on the Terminal window (note the space after the -i) instead of /movie and ~/Desktop/TestMovie instead of /movies/filename

getting on the same page

cd ~/HandBrake

if you're familiar with command line applications this guide is probably not for you, just check out the built-in help and skim/skip through this guide

HandBrakeCLI -h

(new, hopefully more useful) examples

getting a bunch of useful information about the DVD you're going to encode
HandBrakeCLI -i /movie -t 0 useful information

and so on, it's always informative to have a look at this stuff if you're encoding from an unknown source

mimicking the default settings from the gui
HandBrakeCLI -i /movie -o /movies/filename.mp4

pretty straightforward, every option you leave out gets the default value, which happen to be the same as the gui

not terribly useful though

encoding more than one audio track
HandBrakeCLI -i /movie -o /movies/filename.mp4 -a 1,2
or
HandBrakeCLI -i /movie -o /movies/filename.mp4 -a 3,5,7,9
encoding for speed or devices with a low resolution
HandBrakeCLI -i /movie -o /movies/filename.mp4 -p -X 640 -Y 480 -b 500

remember, for every setting you don't specifically set the default value gets inserted

encoding for quality or devices with a high resolution
HandBrakeCLI -i /movie -o /movies/filename.mp4 -m -e x264 -q 0.60 -Q
getting decent audio
HandBrakeCLI -i /movie -o /movies/filename.mp4 -B 192 -R 48 -6

-q 0.60 might not be high enough quality for some, so you can just increment by 0.02 until you hit a quality/file size ratio that feels better for you. for others it might be too much. try big jumps first to find your range, like 0.50 or 0.70, then start increasing or decreasing by 0.02.

the new mencoder style x264 encoder options in exchange for processing time
HandBrakeCLI -i /movie -o /movies/filename.mp4 -m -p -e x264 -q 0.56 -Q -x subq=7:partitions=all:frameref=6:qcomp=1:b_pyramid:weight_b:threads=4

for some reason x264 in HandBrake does not understand the me=XXX option, and neither QuickTime nor VLC can playback files with the 8x8dct or bframes= options; I did not try to test every option, these are just my quick observations

an explanation of the x264 encoder options is well beyond the scope of this document; the reader is urged to reference real documentation. the example above is adapted directly from the mencoder guide linked above.

(old, but hopefully still useful) examples

changing/configuring the encoder

-e chooses the encoder; in this case we use the x264 encoder

HandBrakeCLI -i /movie -o /movies/filename.mp4 -e x264

-b sets a constant bitrate in kilobits; in this case we use 1500

HandBrakeCLI -i /movie -o /movies/filename.mp4 -e x264 -b 1500

-q sets a constant quality where 1.0 is the highest quality; in this case we use 0.7

HandBrakeCLI -i /movie -o /movies/filename.mp4 -e x264 -q 0.7

-S sets the final file size in megabytes; in this case we use 700

HandBrakeCLI -i /movie -o /movies/filename.mp4 -e x264 -S 700

-b, -q and -S are mutually exclusive, the use of any one eliminates the use of the other two.

MP4 file
HandBrakeCLI -i /movie -o /movies/filename.mp4 -a 1,5 -R 48000 -B 192 -e xvid -q 0.94 -s 1 -d -w 512
AVI file
HandBrakeCLI -i /movie -o /movies/filename.avi -E ac3 -e x264 -b 1600
OGM file
HandBrakeCLI -i /movie -o /movies/filename.ogm -E vorbis -R 24000 -B 64 -e xvid -S 150 -g -2 -w 480 -l 480
iPod MP4
HandBrakeCLI -i /movie -o /movies/filename.mp4 -e x264b13 -b 500 -R 44100 -B 128 -2 -w 320

for a lot more information on encoding for your iPod refer to the HandBrake Forums