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- + subtitle tracks:
+ 1, English
to include subtitles for this example you'd just add:-s 1 - + title 5:
+ vts 5, ttn 1, cells 0->18 (1832415 blocks)
+ duration: 01:17:08
+ size: 720x480, aspect: 1.78, 23.976 fps
this tells us title 5 is the "main feature title" (usually the longest), so to make sure you encode the proper title in this example you'd just add:-t 5
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
- mp4 file format
- no chapter markers
- single pass FFMPEG video encoder at 1000kbps
- frame rate: same as original
- AAC audio encoder at 128kbps/44100Hz
- no deinterlacing
- default size
- auto-cropping
- default title and all chapters
- no subtitles
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
- -p: Store pixel aspect ratio in video stream
- -X 640: Set maximum width to 640 pixels
- -Y 480: Set maximum height to 480 pixels
- -b 500: Set video bitrate to 500kbps
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
- -m: Add chapter markers (mp4 output format only)
- -e x264: Set video library encoder to x264 (h.264 compatible and generally superior)
- -q 0.60: Set video quality to 0.70 out of 1.0
- -Q: Use with -q for CRF instead of CQP
getting decent audio
HandBrakeCLI -i /movie -o /movies/filename.mp4 -B 192 -R 48 -6
- -B 192: Set audio bitrate to 192kbps
- -R 48: Set audio samplerate to 48kHz
- -6: Export 5.1 surround as 6-channel AAC
-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
- -e xvid - XviD codec
- -q 0.94 - constant video quality 94%
- -s 1 - subtitle track 1
- -w 512 - 512 pixels wide, height to be calculated by HandBrakeCLI
- -a 1,5 - audio from tracks 1 & 5
- -R 48000 - audio sample rate of 48000Hz
- -B 192 - audio bitrate of 192kbps
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
- -e x264 - x264 codec
- -b 1600 - average video bitrate of 1600kbps
- -E ac3 - Dolby Digital audio
- width & height to be calculated by HandBrakeCLI
HandBrakeCLI -i /movie -o /movies/filename.avi -E ac3 -e x264 -b 1600
OGM file
- -e xvid - XviD codec
- -S 150 - target size of 150MB
- -E vorbis - OGG audio
- -B 64 - audio bitrate of 64kbps
- -R 24000 - audio sample rate of 24000Hz
- -w 480 -l 480 - forces a 1:1 aspect ratio and output size of 480x480 pixels
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
- -e x264b13 - x264 (baseline profile) codec
- -b 500 - average video bitrate of 500kbps
- -R 44100 - audio sample rate of 44100
- -B 128 - audio bitrate of 128kbps
- -2 - two-pass encoding
- -w 320 - width of 320 pixels
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