-
-
Save alecjacobson/60fb2e027e0d4aef60c6 to your computer and use it in GitHub Desktop.
Give HandbrakeCLI a path to a file or a directory and it will generate better-compressed "{.}-handbrake.mp4" files next to each video.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# brew install handbrake parallel ffmpeg | |
usage() | |
{ | |
echo 1>&2 "Usage:" "$0" 'path/to/video/dir1 [path/to/video/dir2 ...]' | |
exit -1 | |
} | |
if [ $# -lt 1 ] | |
then | |
usage | |
fi | |
find "$@" \( -iname '*.mov' -or -iname '*.mpg' -or -iname '*.mpeg' -or \ | |
-iname '*.mp4' -or -iname '*.webm' -or -iname '*.avi' -or -iname '*.wmv' \ | |
-or -iname '*.mkv' -or -iname '*.m4v' \) -print0 | \ | |
parallel -0 --tty \ | |
"ffmpeg -i '{}' -vcodec copy -acodec copy -metadata:s:v:0 rotate=0 \ | |
'{.}-unrotated.mov' && \ | |
HandBrakeCLI -i '{.}-unrotated.mov' -o '{.}-unrotated-handbrake.mp4' -O \ | |
--preset 'Normal' --crop 0:0:0:0 && \ | |
ffmpeg -i '{.}-unrotated-handbrake.mp4' -vcodec copy -acodec copy \ | |
-metadata:s:v:0 rotate=\`mediainfo --Inform=\"Video;%Rotation%\" '{}'\` \ | |
'{.}-handbrake.mp4' && \ | |
rm '{.}-unrotated-handbrake.mp4' '{.}-unrotated.mov' " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment