HandBrakeCLI

HandBrake is a free open-source video transcoder. It's goal is to help people rip their DVDs and save them to a file on their computer. Although there are ways to extract Blu-rays using a 3rd party application, I will not covert this in details over here. In my case I like to use the MakeMKV software which allows to do a preprocess and remove the Audio and subtitle tracks I don't need.

HandBrake is available for Windows, OS X and for many Linux distributions. For this last one, you can even use the command lines to convert your videos. This is what we will look at this this tutorial.

Getting the HandBrakeCLI tool

Alright, first thing first, let's download and install the CLI version of HandBrake. To do so, use the following command

On a Debian base distribution, do the following.
apt-get install handbrake-cli

On ArchLinux based distibution, do the following.
pacman -S handbrake-cli

You can access the latest built throught the AUR (Arch User Repository)
apacman -S handbrake-cli-git

Scanning the content with HandBrakeCLI

HandBrake can now be access through command line. Although, make sure you type the following using the H, B, C, L and I capital letters.

HandBrakeCLI

Now lets look at some flags. HandBrake is pretty explicit with his flag which is really great. They almost use the keyboard twice (so many settings!!!!). The two followings are mostly generic flags. They will allow you to get in the help/manual, check if there is an update, select your input device/file name and output file name.

-h	help
-u	check for updates

-i	Input file name or input device (i.e. DVD Player)
-o	Output file name and location

Let say we want to scan the input to know what is the content. We may do this by two ways. I tend to find -t misleading if used with a 0 so I prefer the second option.

-t	title to encode (by using 0 it will automatically can the input)
--scan	scan the input and display its information
--min-duration	Minimum duration (in seconds) a video needs to before being scanned


Starting from here, I'll use the 2K version of Sintel to illustrate the commands (you may download the 4K version for free, it's amazing to watch. Keep in mind it was made in 2010 using Blender).

Analysing the --scan output

HandBrakeCLI -i sintel-2k.mp4 --scan

  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2010-09-29 12:52:03
  Duration: 00:14:47.99, start: 0.000000, bitrate: 3660 kb/s
    Stream #0.0(und): Video: h264 (High), yuv420p, 2048x872 [PAR 1:1 DAR 256:109], 3526 kb/s, 24 fps, 1k tbn, 48 tbc (default)
    Metadata:
      creation_time   : 1970-01-01 00:00:00
    Stream #0.1(und): Audio: aac, 44100 Hz, stereo, fltp, 127 kb/s (default)
    Metadata:
      creation_time   : 2010-09-29 12:52:24
[21:41:02] scan: decoding previews for title 1
Scanning title 1 of 1, preview 1, 10.00 %[21:41:02] scan: audio 0x1: aac, rate=44100Hz, bitrate=127998 Unknown (AAC) (2.0 ch)
Scanning title 1 of 1, preview 10, 100.00 %[21:41:02] scan: 10 previews, 2048x872, 24.000 fps, autocrop = 0/0/0/0, aspect 2.35:1, PAR 1:1
[21:41:03] libhb: scan thread found 1 valid title(s)
+ title 1:
  + stream: /media/hd1/Videos/Movies-Eng/Sintel (2010).mp4
  + duration: 00:14:47
  + size: 2048x872, pixel aspect: 1/1, display aspect: 2.35, 24.000 fps
  + autocrop: 0/0/0/0
  + support opencl: no
  + support hwd: not built-in
  + chapters:
    + 1: cells 0->0, 0 blocks, duration 00:14:47
  + audio tracks:
    + 1, Unknown (AAC) (2.0 ch) (iso639-2: und)
  + subtitle tracks:


Alright, what is all this? Let's look in short pieces at a time.

The following might be the first information you want to know about your video.

Duration: 00:14:47.99, start: 0.000000, bitrate: 3660 kb/s
    Stream #0.0(und): Video: h264 (High), yuv420p, 2048x872 [PAR 1:1 DAR 256:109], 3526 kb/s, 24 fps, 1k tbn, 48 tbc (default)

You can see that the length of the video is 14:48. That could be something important when you scan a DVD. It will allow you to detect what file is the main title. If you get the extened edition of a movie, you may see one with more time. That is the one you want to use.

An other good information is the video bitrate of 3526 kbps and the 24 frame per seconds (fps)

Scanning title 1 of 1, preview 1, 10.00 %[21:41:02] scan: audio 0x1: aac, rate=44100Hz, bitrate=127998 Unknown (AAC) (2.0 ch)
Scanning title 1 of 1, preview 10, 100.00 %[21:41:02] scan: 10 previews, 2048x872, 24.000 fps, autocrop = 0/0/0/0, aspect 2.35:1, PAR 1:1


In the first line we can the the audio information. This audio has a frequency of 44.1 KHz with a bitrate of 128 kbits. They used the AAC encoding for a sterio mode (2.0 ch). The Second line shows some new information about the video like the aspect ratio and the croping done by HandBrake. The cropping is used to remove a number of lines on each edge of the video when you get annoying black of green stripe this is the way to remove them. The crop order is the following: top/bottom/left/right.

+ chapters:
    + 1: cells 0->0, 0 blocks, duration 00:14:47
  + audio tracks:
    + 1, Unknown (AAC) (2.0 ch) (iso639-2: und)
  + subtitle tracks:


When you ripped a movie from a DVD or Bluray, you may want to only check those last lines. They will tell your the audio and subtitle track numbers and language (we will look at those in the next section).