HandBrakeCLI

Install:

sudo add-apt-repository ppa:stebbins/handbrake-git-snapshots
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

# change the token separator to so you can loop over filenames with spaces
IFS=$(echo -en "\n\b") 

# set some default encoding options
QUALITY=25
TUNE=film
AENCODER=av_aac


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


# if the source looks interlaced
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

# uses QUALITY,TUNE, etc from above

for X in `ls *.mkv`; do HandBrakeCLI -i "$X" -o "output/$X" --encoder x265 --encoder-preset slower -q $QUALITY --nlmeans --nlmeans-tune $TUNE --subtitle 1 --aencoder $
AENCODER --mixdown 6ch;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 `ls *.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 2ch; 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