Using Handbrake for conversion

Wednesday, January 20, 2010 Posted by Psyk
I've been playing around with HandBrake for a little while now and it's a very good and versatile encoder.  One of the reasons I like it so much is that it combines two of my favourite encoders being FFmpeg and Mencoder.

One of the more challenging items is adjusting the aspect ratio of your final video. It requires some understanding of Pixel Aspect Ratio which is different to your standard aspect ratio. I won't go into detail here, but basically to change your video format from 4:3 to 16:9 you'll need to feed the PAR parameters.

Here are the rough PAR specs on standard DVD's.
NTSC 4:3 - storage resolution 720 x 480,PAR 8/9 - display resolution 640 x 480 (= 4:3 aspect ratio)
NTSC 16:9 - storage resolution 720 x 480,PAR 32/27 - display resolution 853 x 480 (= 16:9 aspect ratio)
PAL 4:3 - storage resolution 720 x 576,PAR 16/15 - display resolution 768 x 576 (= 4:3 aspect ratio)
PAL 16:9 - storage resolution 720 x 576,PAR 64/45 - display resolution 1024 x 576 (= 16:9 aspect ratio)

Under HandBrake I've been using the preset settings for doing the encode and they're working well. Here's a list of the preset settings as per 0.94 of Handbrake:
 Apple:  
 Universal: -e x264 -q 20.0 -a 1,1 -E faac,ac3 -B 160,160 -6 dpl2,auto -R 48,Auto -D 0.0,0.0 -f mp4 -X 720 --loose-anamorphic -m -x cabac=0:ref=2:me=umh:bframes=0:8x8dct=0:trellis=0:subme=6  
 iPod: -e x264 -b 700 -a 1 -E faac -B 160 -6 dpl2 -R 48 -D 0.0 -f mp4 -I -X 320 -m -x level=30:bframes=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1:subme=6:8x8dct=0:trellis=0  
 iPhone & iPod Touch: -e x264 -q 20.0 -a 1 -E faac -B 128 -6 dpl2 -R 48 -D 0.0 -f mp4 -X 480 -m -x cabac=0:ref=2:me=umh:bframes=0:subme=6:8x8dct=0:trellis=0  
  AppleTV: -e x264 -q 20.0 -a 1,1 -E faac,ac3 -B 160,160 -6 dpl2,auto -R 48,Auto -D 0.0,0.0 -f mp4 -4 -X 960 --loose-anamorphic -m -x cabac=0:ref=2:me=umh:b-adapt=2:weightb=0:trellis=0:weightp=0  
 ----  
 Regular  
 Normal: -e x264 -q 20.0 -a 1 -E faac -B 160 -6 dpl2 -R 48 -D 0.0 -f mp4 --strict-anamorphic -m -x ref=2:bframes=2:subme=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0  
 High Profile: -e x264 -q 20.0 -a 1,1 -E faac,ac3 -B 160,160 -6 dpl2,auto -R 48,Auto -D 0.0,0.0 -f mp4 --detelecine --decomb --loose-anamorphic -m -x b-adapt=2:rc-lookahead=50  
 ----  
 Legacy  
 Classic: -b 1000 -a 1 -E faac -B 160 -6 dpl2 -R 48 -D 0.0 -f mp4  
 AppleTV Legacy: -e x264 -b 2500 -a 1,1 -E faac,ac3 -B 160,160 -6 dpl2,auto -R 48,Auto -D 0.0,0.0 -f mp4 -4 --strict-anamorphic -m -x ref=1:subme=5:me=umh:no-fast-pskip=1:cabac=0:weightb=0:8x8dct=0:trellis=0  
 iPhone Legacy: -e x264 -b 960 -a 1 -E faac -B 128 -6 dpl2 -R 48 -D 0.0 -f mp4 -I -X 480 -m -x level=30:cabac=0:ref=1:analyse=all:me=umh:no-fast-pskip=1:psy-rd=0,0:bframes=0:subme=6:8x8dct=0:trellis=0  
 iPod Legacy: -e x264 -b 1500 -a 1 -E faac -B 160 -6 dpl2 -R 48 -D 0.0 -f mp4 -I -X 640 -m -x level=30:bframes=0:cabac=0:ref=1:vbv-maxrate=1500:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1:psy-rd=0,0:subme=6:8x8dct=0:trellis=0  

The Normal and High-Profile settings should work just find on a PS3.

As an example, here are the details on a source DVD I'm encoding for the kids:

  • + title 1:
  • + vts 0, ttn 0, cells 0->0 (0 blocks)
  • + angle(s) 0
  • + duration: 00:39:46
  • + size: 720x576, pixel aspect: 16/15, display aspect: 1.33, 25.000 fps
  • + autocrop: 0/0/12/6
  • + chapters:
  • + 1: cells 0->0, 0 blocks, duration 00:39:46
  • + audio tracks:
  • + 1, Unknown (AC3) (2.0 ch) (iso639-2: und), 48000Hz, 224000bps
  • + subtitle tracks:
  • + combing detected, may be interlaced or telecined
The aspect is 4:3 with a pixel aspect of 16/15.

Another way to pick up the aspect and Pixel Aspect Ratio (PAR) parameters is to use FFmpeg.
For example, you could do something like ffmpeg -i movie.vob :




$ffmpeg -i movie.vob  
 Seems stream 0 codec frame rate differs from container frame rate: 59.94 (60000/1001) -> 29.97 (30000/1001) 
 Input #0, mpeg, from 'mvoie.vob': 
  Duration: 00:03:08.18, start: 0.060000, bitrate: 6939 kb/s 
   Stream #0.0[0x1e0]: Video: mpeg2video, yuv420p, 720x480 [PAR 8:9 DAR 4:3], 8000 kb/s, 29.97 tbr, 90k tbn, 59.94 tbc 
   Stream #0.1[0xa0]: Audio: pcm_s16be, 48000 Hz, stereo, s16, 1536 kb/s 
 At least one output file must be specified 



You'll note the PAR is 8:9 and DAR is 4:3 which matches an NTSC DVD as per above.  Applying a
--pixel-aspect 32:27 in Handbrake would change this to a Widescreen format.

By using HandBrake I was able to re-encode to a compliant MP4 with the correct wide-screen aspect display. The size of the file was slightly larger and the resolution increased slightly from 720x576 (or 704 with cropping) to 1001x576 (with cropping) in Widescreen format. Very handy tool this HandBrake :)

Here's the command I used:
 HandBrakeCLI -v -i source.avi -o target.mp4 --deinterlace --size 700 -e x264 -a 1 -E faac -B 160 -6 dpl2 -R 48 -D 0.0 -f mp4 --custom-anamorphic --pixel-aspect 64:45 -m -x ref=2:bframes=2:subme=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0   
Labels:

Post a Comment