Skip to content

Instantly share code, notes, and snippets.

@yig
Last active September 13, 2019 21:26
Show Gist options
  • Save yig/134ed7687aa0cffc8fba to your computer and use it in GitHub Desktop.
Save yig/134ed7687aa0cffc8fba 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.
#!/bin/bash
## Depends on Handbrake command line tool, which you can download as a binary: https://handbrake.fr/downloads2.php
## This script calls it recursively on all videos found. As a one off, the command is:
# HandBrakeCLI -i path/to/input -o path/to/output.mp4' -O --preset 'Normal' --crop 0:0:0:0
usage()
{
echo 1>&2 "Usage:" "$0" 'path/to/video/dir1 [path/to/video/dir2 ...]'
exit -1
}
if [ $# -lt 1 ]
then
usage
fi
## -O or --optimize: Rearranges MP4 files so they play better over the web as progressive downloads.
## Rotation: http://superuser.com/questions/418985/can-handbrake-flip-rotate-a-video
## Add --rotate 4 to rotate 90 degrees clockwise.
## Add --rotate 7 to rotate 90 degrees counter-clockwise.
## Add --rotate 3 to rotate 180 degrees.
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 HandBrakeCLI -i '{}' -o '{.}-handbrake.mp4' -O --preset 'Normal' --crop 0:0:0:0
@alecjacobson
Copy link

I can't manage to get the rotate commands to work correctly on 90 degree "vertical" videos from an iphone. For any of the options, I either get 0 rotation or 180 rotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment