HandBrakeCLI

Install:

# Sometimes the snapshot repo is actually behind the main one, so apt search and compare versions
# sudo add-apt-repository ppa:stebbins/handbrake-git-snapshots
sudo add-apt-repository ppa:stebbins/handbrake-releases
sudo apt-get update
sudo apt-get install handbrake-cli

Use:

# Note:
# I'm using the newer x265 codec and the MKV container. 

# Bluray: -q 25 is usually indistinguishable from source when played (though not as a still).
# DVD: -q 20 is usually visually adequate.

Do a test run to see how the encodes will look

# make an output directory and pick a test file
mkdir output
SOURCE=someSource.mkv

# See if the sources are non 24 fps (and so likely interlaced or telecined)
for X in *.mkv; do echo $X;mkvinfo "$X" | grep -B 1 "Video track";echo;done

# if the source looks interlaced or has 29.970 frames/fields per second
for X in " " "--detelecine" "--decomb" "--deinterlace";do HandBrakeCLI -i "$SOURCE" -o "output/test_$X.mkv" -e x265 --encoder-preset faster $X --start-at duration:150 --stop-at duration:60;done


# Test the effect of the nlmeans filter for size reduction vs detail loss visually
for X in " " "--nlmeans";do HandBrakeCLI -i "$SOURCE" -o "output/test_$X.mkv" -e x265 --encoder-preset faster $X --start-at duration:150 --stop-at duration:60;done


Loop over a directory of ripped mkv files with basic options

# for DVD that you want the first audio track and first subtitle track and want to preserve the surround sound.
QUALITY=20
TUNE=film
AENCODER=aac

for X in *.mkv; do HandBrakeCLI -i "$X" -o "output/$X" --encoder x265 --encoder-preset slower --quality $QUALITY --nlmeans --nlmeans-tune $TUNE --subtitle 1 --aencoder $
AENCODER --mixdown 5point1;done


Adjust for alternate source type

# for anime DVD with second audio track and multi track subs and audio encoded 2 channel opus
QUALITY=20
TUNE=animation
AENCODER=opus


for X in *.mkv; do HandBrakeCLI -i "$X" -o "output/$X" --encoder x265 --encoder-preset slower -q $QUALITY --nlmeans --nlmeans-tune $TUNE --aencoder $AENCODER --subtitle 1,2,3 --audio 1,2 --mixdown stereo; done

Other, interesting scenarios

# For a DVD source that has several titles and subtitle streams, and select chapters 
HandBrakeCLI -i VIDEO_TS -o Output_File.m4v --title 1 --chapters 3-7  --x264-preset slower -q 23 --subtitle 2

# For Blu Ray with DTS that you are converting to AC3 for your surround system
HandBrakeCLI -i someMovie.mkv -o Output_File.m4v --x264-tune film --x264-preset slow -q 20 --aencoder ac3 --mixdown 6ch

# For a web optimized mp4
HandBrakeCLI -i someSource.mkv -o Output_File.mp4 --x264-preset slower --optimize

Links

Installation and Use:
    
    http://askubuntu.com/questions/107915/how-do-i-download-and-install-handbrake
    https://trac.handbrake.fr/wiki/CLIGuide


nlmeans tuning translations

    https://github.com/HandBrake/HandBrake/blob/master/libhb/param.c

Comparing Quality Values

    http://mattgadient.com/2013/06/20/comparing-x264-rf-settings-in-handbrake-examples/

De-Noising

    http://mattgadient.com/2013/06/29/in-depth-look-at-de-noising-in-handbrake-with-imagevideo-examples/

Comments