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

IFS=$(echo -en "\n\b")
SOURCE=someSource.mkv

# if the source looks interlaced
for X in " " "--detelecine" "--decomb" "--deinterlace";do HandBrakeCLI -i "$SOURCE" -o "output$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$X.mkv" -e x265 --encoder-preset faster $X --start-at duration:150 --stop-at duration:60;done

Loop over a directory of bluray source files

# Loop over all the .mkv files and encode
for X in `ls *.mkv`; do Y=`echo $X | sed 's/.mkv/.new.mkv/'`; HandBrakeCLI -i "$X" -o "$Y" -e x265 --encoder-preset slower -q 25 --nlmeans --nlmeans-tune film --subtitle 1 --aencoder opus;done

# Rename all the files
for X in `ls *.new.mkv`; do Y=`echo $X|sed 's/\.new.mkv/.mkv/'`;mv "$X" "$Y";done

For DVD source files

# For DVD 
HandBrakeCLI -i "$X" -o "$Y" -e x265 --encoder-preset slower -q 20 --nlmeans --nlmeans-tune film --subtitle 1 --aencoder fdk_aac --mixdown 6ch

# For anime DVD with second audio track 
HandBrakeCLI -i "$X" -o "$Y" -e x265 --encoder-preset slower -q 20 --nlmeans --nlmeans-tune animation --subtitle 1,2,3 --audio 1,2 --aencoder fdk_aac --mixdown 6ch

# To run a test, add some duration arguments
--start-at duration:150 --stop-at duration:60





# Older notes  

  # For modern, hi quality sources. 
  # Uses the default quality setting of 20, AAC audio and optimizes playbak
HandBrakeCLI -i someSource.mkv -o Output_File.m4v --x264-preset slower --optimize

  # For older films that may have some interlacing that can use a little denoising
HandBrakeCLI -i someSource.mkv -o Output_File.m4v --x264-preset slower --nlmeans --nlmeans-tune film --decomb --optimize

  # For fairly old and noisy lower res tv shows. q 23 is visually the same as older sources
HandBrakeCLI -i someSource.mkv -o Output_File.m4v -q 23 --optimize --nlmeans medium --nlmeans-tune film --decomb --optimize

  # 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 --decomb --optimize

# 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


Scripting:

IFS=$(echo -en "\n\b")
for X in `ls *.mkv`; do Y=`echo $X | sed 's/.mkv/.m4v/'`;HandBrakeCLI -i "$X" -o "$Y" --x264-preset slower --x264-tune film --optimize;done

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