How to Use 'handbrakecli' (with Examples)

How to Use 'handbrakecli' (with Examples)

HandBrakeCLI is the command-line interface version of the popular HandBrake video conversion software. It allows users to convert and encode video files, making it an indispensable tool for video enthusiasts and professionals alike. Leveraging its powerful features, users can rip DVDs, manage video quality, resize video dimensions, and select presets for targeted conversion tasks—all through command-line operations. Whether you’re looking to convert videos to different formats or optimize file size and quality, HandBrakeCLI provides a flexible and robust solution.

Use Case 1: Convert a Video File to MKV Format with Specified Audio and Video Quality

Code:

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

Motivation:

This use case exemplifies the process of converting a video file to the MKV format while setting specific audio and video quality parameters. Families with vast video collections might want to standardize their formats to MKV for better compatibility and storage efficiency. Additionally, optimizing video and audio quality ensures a seamless viewing experience without compromising the integrity of the content.

Explanation:

  • --input input.avi: Specifies the input file to be converted. In this example, ‘input.avi’ is the file that needs conversion.
  • --output output.mkv: Determines the name and format of the output file, ‘output.mkv’ in this case.
  • --encoder x264: Chooses x264 as the video encoder, a popular option known for high efficiency in video compression.
  • --quality 20: Sets the Constant Rate Factor (CRF) to 20, balancing file size and video quality.
  • --ab 160: Specifies the audio bitrate at 160 kbit/s, which ensures decent audio quality while keeping file size in check.

Example Output:

Upon successful execution, the command returns a new MKV file, ‘output.mkv’, with the desired video and audio quality settings.

Use Case 2: Resize a Video File to 320x240

Code:

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

Motivation:

Resizing a video is essential for compatibility with devices having specific screen resolutions or for reducing file size for faster streaming. A use case scenario might be adjusting video dimensions for compatibility with old mobile devices or embedding into web interfaces where larger dimensions aren’t necessary.

Explanation:

  • --input input.mp4: Points to the source video file that is to be resized.
  • --output output.mp4: Defines the name of the resulting file after resizing.
  • --width 320: Sets the width of the video to 320 pixels.
  • --height 240: Sets the height of the video to 240 pixels.

Example Output:

After the process is complete, the resized video ‘output.mp4’ displays a dimension of 320x240 pixels as specified.

Use Case 3: List Available Presets

Code:

handbrakecli --preset-list

Motivation:

Presets are predefined settings tailored to various devices and output needs. Listing available presets helps users quickly identify the right configuration for their specific needs, enhancing the ease and efficiency of video conversion tasks.

Explanation:

  • --preset-list: This command invokes a list of all available conversion presets within HandBrakeCLI.

Example Output:

The command outputs a list of preset names, each corresponding to specific configurations like ‘Android’, ‘iPod’, or ‘Web’, among others, providing users with numerous options to suit their requirements.

Use Case 4: Convert an AVI Video to MP4 Using the Android Preset

Code:

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

Motivation:

Using a preset like ‘Android’ ensures that the output video is optimized for Android devices, taking the guesswork out of the conversion process. This use case is particularly beneficial for users looking to play their videos on Android phones or tablets without compatibility issues.

Explanation:

  • --preset="Android": Utilizes the ‘Android’ preset to apply settings best suited for Android devices.
  • --input input.ext: Refers to the source video file extension to be converted, which in this case is ‘input.ext’.
  • --output output.mp4: Specifies the name and format for the converted video file.

Example Output:

The resulting ‘output.mp4’ is formatted with settings that are compatible with Android devices, ensuring smooth playback.

Use Case 5: Print the Content of a DVD, Getting the CSS Keys in the Process

Code:

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

Motivation:

Accessing a DVD’s content and retrieving the CSS encryption keys allows users to analyze the structure and content of the DVD. This process can be necessary for archival purposes or when troubleshooting compatibility issues with DVD playback.

Explanation:

  • --input /dev/sr0: Points to the DVD drive containing the disc that needs to be analyzed.
  • --title 0: Requests details of the entire DVD, including content structure and encryption keys.

Example Output:

The command prints metadata of the DVD, displaying details such as available titles, chapters, audio tracks, and encryption information.

Use Case 6: Rip the First Track of a DVD with Specified Audio and Subtitle Settings

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:

Ripping specific tracks from a DVD with chosen audio and subtitles is valuable for users who aim to compile their favorite scenes or create a personalized viewing experience. It is particularly helpful in creating backups or converting content for portable devices.

Explanation:

  • --input /dev/sr0: Denotes the DVD drive as the input source.
  • --title 1: Specifies the title or track number on the DVD to rip.
  • --output out.mkv: Names the output file, ‘out.mkv’, in this scenario.
  • --format av_mkv: Sets the output container format to Matroska (MKV).
  • --encoder x264: Utilizes x264 for video encoding.
  • --subtitle 1,4,5: Selects subtitle tracks 1, 4, and 5 for inclusion in the output.
  • --audio 1,2: Chooses audio tracks 1 and 2 for inclusion.
  • --aencoder copy: Indicates audio should be copied without re-encoding.
  • --quality 23: Adjusts the video quality with a CRF setting of 23.

Example Output:

The process yields an MKV file named ‘out.mkv’, containing the first track of the DVD with specified audio and subtitle tracks, encoded using x264 for video.

Conclusion:

HandBrakeCLI offers a highly versatile command-line tool for video conversion and DVD ripping, providing numerous options to customize video output to match various requirements. By understanding and utilizing the different arguments and presets available, users can achieve their desired video outcomes efficiently with HandBrakeCLI.

Related Posts

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

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

The finger command is a utility in Unix-like operating systems that provides users with information about other system users.

Read More
How to Use the Command 'mitmweb' (with Examples)

How to Use the Command 'mitmweb' (with Examples)

The mitmweb command serves as a powerful tool for network forensics and debugging, acting as a web-based interactive man-in-the-middle HTTP proxy.

Read More
How to Use the 'mytop' Command (with Examples)

How to Use the 'mytop' Command (with Examples)

The ‘mytop’ command is a powerful tool for monitoring MySQL database performance, akin to the Unix ’top’ command but specifically tailored for MySQL.

Read More