How to Install Handbrake and Convert recursive file tree's
Questions:
- Install Handbrake cli
- Create script to convert all files further down file tree from script
- Get example options from GUI
- Automate because I'm lazy [actually I just value my time :)]
- Installing Just handbrake CLI, I use a headless server and windows front end!
For Newest Builds Recommended as Stables released yearly...
sudo add-apt-repository ppa:stebbins/handbrake-snapshots && sudo apt-get update && sudo apt-get install handbrake-cli
For Stable Releases
sudo add-apt-repository ppa:stebbins/handbrake-releases && sudo apt-get update && sudo apt-get install handbrake-cli
-
Uncomment the line you wish to use and the file type. You can add many more "presets/FLAGS", this is just an idea. The original script had issues when converting MP4 files to MP4 due to naming conflicts.
#!/bin/bash #Uncomment a Preset FLAGS and Uncomment a file type (mkv,avi,mp4)! # This Script Goes in Root Folder of TV show -- Example Folder Structure # /Stargate/Season\ 1/Epiosde.avi # /Stargate/Season\ 2/Epiosde.avi # /Stargate/handbrake.script # Outputs all Files back inside same dir's and does all folders inside Startgate DIR # /Stargate/Season\ 1/Epiosde.mp4 # /Stargate/Season\ 2/Epiosde.mp4 # FLAGS = flags for CLI can be got from GUI under Activity Log (In some versions) or from https://trac.handbrake.fr/wiki/CLIGuide (Flags can not have spaces, IE: No Presets, and can't have "'s, but you can just delete them, like --decomb="bob", the CLI accepts --decomb=bob ###Encode AC3 5.1 #export FLAGS="-f mp4 -O --decomb=bob --loose-anamorphic --modulus 2 -e x264 -q 20 --vfr -E ac3 -6 5point1 -R 48 -B 448 --audio-fallback ac3 --encoder-preset=veryfast --verbose=1" ###COPY AC3 5.1 #export FLAGS="-f mp4 -O --decomb=bob --loose-anamorphic --modulus 2 -e x264 -q 20 --vfr -E copy:ac3 --audio-fallback ac3 --encoder-preset=veryfast --verbose=1" ###Denoise & Encode AC3 5.1 #export FLAGS="-f mp4 -O --decomb=bob --nlmeans=medium --loose-anamorphic --modulus 2 -e x264 -q 20 --vfr -E ac3 -6 5point1 -R 48 -B 448 --audio-fallback ac3 --encoder-preset=veryfast --verbose=1" ###Denoise & COPY AC3 5.1 #export FLAGS="-f mp4 -O --decomb=bob --nlmeans=medium --loose-anamorphic --modulus 2 -e x264 -q 20 --vfr -E copy:ac3 --audio-fallback ac3 --encoder-preset=veryfast --verbose=1" if [ -z "$1" ] ; then TRANSCODEDIR="." else TRANSCODEDIR="$1" fi ###To use [&& find . -name '*.***' -delete] Uncomment and delete once to add to previous line of code ###Removes source files after completing ALL conversions. Use at your own risk! #AVI #find "$TRANSCODEDIR"/* -type f -name "*.avi" -exec bash -c 'HandBrakeCLI -i "$1" -o "${1%\.*}".mp4 $FLAGS' __ {} \; #&& find . -name '*.avi' -delete #MKV #find "$TRANSCODEDIR"/* -type f -name "*.mkv" -exec bash -c 'HandBrakeCLI -i "$1" -o "${1%\.*}".mp4 $FLAGS' __ {} \; #&& find . -name '*.mkv' -delete #MP4 #find "$TRANSCODEDIR"/* -type f -name "*.mp4" -exec bash -c 'HandBrakeCLI -i "$1" -o "${1%\.*}"-new.mp4 $FLAGS' __ {} \; ##&&find . -type f -not -name '*-new.mp4' -name '*.mp4' -delete && rename 's/-new//' *.mp4
-
I Used the windows program and tested till I found my perfect settings then run it on a file and click activity window >> encode log >> (AT BEGINNING OF LOG) this is what I got.
CLI Query: -i "C:\Users\donut\Downloads\TobeConverted\Love & Other Drugs (2010).avi" -t 1 --angle 1 -c 1 -o "C:\Users\donut\Downloads\ConvertedMedia\Love & Other Drugs (2010).mp4" -f mp4 -w 720 --crop 68:70:0:0 --loose-anamorphic --modulus 2 -e x264 -q 20 --vfr -a 1 -E ac3 -6 5point1 -R Auto -B 384 -D 0 --gain 0 --audio-fallback ac3 --markers="C:\Users\donut\AppData\Local\Temp\Love & Other Drugs (2010)-1-chapters.csv" --encoder-preset=veryfast --encoder-level="5.2" --encoder-profile=high --verbose=1
The simple version is
HandBrakeCLI -i source [flags] -o destination [flags]
So I had to remove
--markers="C:\Users\donut\AppData\Local\Temp\Love & Other Drugs (2010)-1-chapters.csv"
-
My Alias for unattended use.
alias handfolder="sudo cp /media/handbrake.script ./ && sudo nano ./handbrake.script ; nohup ./handbrake.script > handbrake.nohup &"
where the script is named handbrake.script and placed in /media/handbrake.script. Use this alias when in the bottom of the directories you want to recursively convert!