LinuxCommandLibrary

handbrakecli

Convert video from one format to another

TLDR

Convert a video file to MKV (AAC 160kbit audio and x264 CRF20 video)

$ handbrakecli [[-i|--input]] [input.avi] [[-o|--output]] [output.mkv] [[-e|--encoder]] x264 [[-q|--quality]] 20 [[-B|--ab]] 160
copy

Resize a video file to 320x240
$ handbrakecli [[-i|--input]] [input.mp4] [[-o|--output]] [output.mp4] [[-w|--width]] 320 [[-l|--height]] 240
copy

List available presets
$ handbrakecli [[-z|--preset-list]]
copy

Convert an AVI video to MP4 using the Android preset
$ handbrakecli [[-Z|--preset]] "Android" [[-i|--input]] [input.ext] [[-o|--output]] [output.mp4]
copy

Print the content of a DVD, getting the CSS keys in the process
$ handbrakecli [[-i|--input]] [/dev/sr0] [[-t|--title]] 0
copy

Rip the first track of a DVD in the specified device. Audiotracks and subtitle languages are specified as lists
$ handbrakecli [[-i|--input]] [/dev/sr0] [[-t|--title]] 1 [[-o|--output]] [out.mkv] [[-f|--format]] av_mkv [[-e|--encoder]] x264 [[-s|--subtitle]] [1,4,5] [[-a|--audio]] [1,2] [[-E|--aencoder]] copy [[-q|--quality]] [23]
copy

SYNOPSIS

HandBrakeCLI [options] -i input_file -o output_file

PARAMETERS

-i, --input path
    Input source file, directory (batch), URL, or DVD/Blu-ray device.

-o, --output path
    Output destination file (required).

--preset name
    Apply built-in preset, e.g., 'Fast 1080p30', 'HQ 2160p60 4K HEVC'.

-f, --format mp4|mkv|webm
    Output container format (default: mp4).

-e, --encoder x264|x265|vp9|mpeg4
    Video encoder.

-q, --quality float
    Constant quality (RF scale 0-50, lower=better).

--vb bitrate
    Average video bitrate in kbps.

-2, --two-pass
    Enable two-pass encoding.

--turbo-first-pass
    Fast first pass in 2-pass mode.

-r framerate
    Video framerate (e.g., 30, 60, 'same').

--cfr
    Force constant framerate.

--vfr
    Variable framerate (default).

-w width
    Output picture width.

-l height
    Output picture height.

-a tracks
    Audio track indices (1-based, comma-separated).

--aencoder encoder
    Audio encoder (aac, ac3, copy, etc.).

--ab bitrate
    Audio bitrate in kbps.

-s tracks
    Subtitle track indices (burn-in with 'burn:track').

--crop top:bottom:left:right
    Pixels to crop (auto by default).

--deinterlace
    Enable deinterlace filter.

--denoise hq|light|medium
    Denoise filter strength.

--decomb
    Decomb filter for telecined content.

--grayscale
    Convert to grayscale.

--rotate angle
    Rotate video (90, 180, 270).

--strict-anamorphic
    Strict anamorphic pixel aspect ratio.

--loose-anamorphic
    Loose anamorphic (default).

--native-language eng
    Prefer source language for audio/subtitles.

--log file
    Log file path.

--log-level error|warning|info|debug
    Logging verbosity.

-Z, --preset-import-file json
    Import custom preset from JSON file.

--preset-export json
    Export current settings as JSON preset.

-t, --title index
    Title/PGM index (default: longest).

-c, --chapters start:end
    Chapter range (default: all).

--encopts key=value:key=value
    Encoder-specific options.

DESCRIPTION

HandBrakeCLI is the powerful command-line interface to the open-source HandBrake video transcoder, enabling conversion of media files from nearly any format (DVD, Blu-ray, MKV, AVI, MP4, etc.) to efficient modern formats like H.264, H.265 (HEVC), VP8/VP9, with audio in AAC, AC3, Opus, and containers such as MP4, MKV, or WebM.

It excels in batch processing, server-side encoding, and scripted workflows, offering presets optimized for devices (iPhone, Android, Apple TV), quality-based or bitrate encoding, two-pass modes for better efficiency, and filters for deinterlacing, denoising, cropping, scaling, rotation, and anamorphic adjustments. Subtitles, chapters, and multiple audio tracks are fully supported with burn-in options.

Leveraging FFmpeg/libav, x264/x265, libvpx, and other libraries, it delivers high-quality results with fine control. Usage suits automation, but requires significant CPU/GPU resources for complex jobs. Install via package managers like apt (sudo apt install handbrake-cli) on Linux.

CAVEATS

Highly CPU-intensive; long encodes may take hours. Requires HandBrake full package for all encoders (e.g., x265). No GPU acceleration in CLI by default. Batch mode scans directories recursively but processes sequentially. Check HandBrakeCLI --help for full/complete list as options evolve.

PRESETS

List presets: HandBrakeCLI --preset-list. Common: 'Very Fast 720p30', 'HQ 1080p30 Surround'. Custom JSON presets via --preset-import-file enable reproducibility.

BATCH PROCESSING

Scan folder: -i /path/to/videos/ --output-dir=/output/. Processes all detected titles automatically.

EXAMPLES

HandBrakeCLI -i input.mkv -o output.mp4 --preset="Fast 1080p30"
HandBrakeCLI -i dvd:///dev/sr0 -o movie.mp4 -t1 --preset="High Profile"
HandBrakeCLI -i input.avi -o output.mkv -e x265 -q 22 -r 24 --deinterlace --crop 0:0:0:0

HISTORY

HandBrake project began in 2003 as a GPL-licensed DVD-to-MPEG-4 ripper for BeOS by Eric Petit. Ported to Linux/Mac in 2004-2006. HandBrakeCLI debuted in HandBrake 0.9.4 (2009), expanding CLI support for automation. Now at version 1.8+ (2024), with ongoing FFmpeg integration, HEVC/VP9 support, and JSON presets.

SEE ALSO

ffmpeg(1), avconv(1), mencoder(1)

Copied to clipboard