How to use the command 'handbrakecli' (with examples)

How to use the command 'handbrakecli' (with examples)

HandBrake is a popular video conversion and DVD ripping tool. The ‘handbrakecli’ command-line interface allows users to access the functionality of HandBrake through the terminal. This article will demonstrate various use cases of the ‘handbrakecli’ command with example code and explanations.

Use case 1: Convert a video file to MKV (AAC 160kbit audio and x264 CRF20 video)

Code:

handbrakecli --input input.avi --output output.mkv --encoder x264 --quality 20 --ab 160

Motivation: This use case is useful when you want to convert a video file to the MKV format with specific audio and video settings. The ‘–encoder x264’ argument ensures the video is encoded using the x264 codec, while the ‘–ab 160’ argument sets the audio bitrate to 160kbit.

Explanation:

  • –input: Specifies the input video file (input.avi in this example).
  • –output: Specifies the output file name and format (output.mkv in this example, where MKV is the format).
  • –encoder: Specifies the video encoder to be used (x264 in this example).
  • –quality: Sets the video quality, where a lower value represents higher quality (20 in this example).
  • –ab: Specifies the audio bitrate in kbit (160 in this example).

Example output: The input.avi video file will be converted to output.mkv with AAC 160kbit audio and x264 CRF20 video.

Use case 2: Resize a video file to 320x240

Code:

handbrakecli --input input.mp4 --output output.mp4 --width 320 --height 240

Motivation: This use case is helpful when you need to resize a video file to a specific resolution. In this example, we resize the input.mp4 video to 320x240 pixel dimensions.

Explanation:

  • –input: Specifies the input video file (input.mp4 in this example).
  • –output: Specifies the output file name and format (output.mp4 in this example, where MP4 is the format).
  • –width: Sets the width of the output video (320 pixels in this example).
  • –height: Sets the height of the output video (240 pixels in this example).

Example output: The input.mp4 video file will be resized to 320x240 pixels and saved as output.mp4.

Use case 3: List available presets

Code:

handbrakecli --preset-list

Motivation: This use case helps users discover the available presets in HandBrake. Presets are pre-configured settings that simplify the conversion process for specific devices or formats.

Explanation: The ‘–preset-list’ argument displays a list of available presets present in HandBrake.

Example output: The command will output a list of available presets, such as ‘Android’, ‘iPhone & iPod Touch’, ‘General’, etc.

Use case 4: Convert an AVI video to MP4 using the Android preset

Code:

handbrakecli --preset="Android" --input input.ext --output output.mp4

Motivation: This example demonstrates how to use a specific preset, in this case, the ‘Android’ preset, to convert an AVI video file to MP4. Using presets simplifies the conversion process by applying pre-configured settings optimized for the target device or format.

Explanation:

  • –preset: Specifies the preset to be used (Android in this example).
  • –input: Specifies the input video file (input.ext in this example).
  • –output: Specifies the output file name and format (output.mp4 in this example, where MP4 is the format).

Example output: The input AVI video file (input.ext) will be converted to an MP4 file (output.mp4) using the ‘Android’ preset.

Use case 5: Print the content of a DVD, getting the CSS keys in the process

Code:

handbrakecli --input /dev/sr0 --title 0

Motivation: This use case is useful when you need to examine the content of a DVD and obtain the CSS keys. CSS keys are used for DVD encryption and can be useful for further analysis or extraction purposes.

Explanation:

  • –input: Specifies the input source, in this case, /dev/sr0, which represents the DVD drive.
  • –title: Specifies the title to be processed (0 in this example represents the first title).

Example output: The command will display the information and content of the DVD, including CSS keys if present.

Use case 6: Rip the first track of a DVD in the specified device

Code:

handbrakecli --input /dev/sr0 --title 1 --output out.mkv --format av_mkv --encoder x264 --subtitle 1,4,5 --audio 1,2 --aencoder copy --quality 23

Motivation: This use case demonstrates how to rip the first track of a DVD using specific settings. The example specifies the output format as MKV, the video encoder as x264, and selects specific subtitles and audio tracks.

Explanation:

  • –input: Specifies the input source, in this case, /dev/sr0, representing the DVD drive.
  • –title: Specifies the title to be processed (1 in this example represents the first title).
  • –output: Specifies the output file name and format (out.mkv in this example, where MKV is the format).
  • –format: Specifies the output format (av_mkv in this example).
  • –encoder: Specifies the video encoder to be used (x264 in this example).
  • –subtitle: Selects specific subtitle tracks to be included (1,4,5 in this example represents subtitle tracks 1, 4, and 5).
  • –audio: Selects specific audio tracks to be included (1,2 in this example represents audio tracks 1 and 2).
  • –aencoder: Specifies the audio encoder to be used (copy in this example, which preserves the original audio format).
  • –quality: Sets the video quality, where a lower value represents higher quality (23 in this example).

Example output: The command will rip the first track of the DVD in /dev/sr0, apply the specified settings, and save the output as out.mkv.

Conclusion:

The ‘handbrakecli’ command-line interface provides a convenient way to utilize HandBrake’s video conversion and DVD ripping capabilities through the terminal. With the various use cases presented in this article, users can perform tasks such as converting video files, resizing videos, exploring available presets, and extracting content from DVDs. Understanding the command’s arguments and their purposes allows for efficient and customized video processing.

Related Posts

How to use the command xtrlock (with examples)

How to use the command xtrlock (with examples)

The xtrlock command is used to lock the X display until the user supplies their password.

Read More
How to use the command 'ropper' (with examples)

How to use the command 'ropper' (with examples)

The ‘ropper’ command is a tool used for finding ROP (Return Oriented Programming) gadgets in binary files.

Read More
ffprobe (with examples)

ffprobe (with examples)

Display all available stream info for a media file The command ffprobe -v error -show_streams input.

Read More