Compress and fix rotation of iPhone videos

Hey all,
I was looking for this for a while and didn't find it, so I hope it's useful to someone here.
I use dropbox to automatically upload my iPhone videos and pictures and have a desktop machine with hazel that fixes the rotation and then converts (and compresses) to m4v.
Anyway, the guts of it is in a script that I call that looks something like this:
Basically I used ffprobe to determine if it needs rotating. If it does I use ffmpeg to do it, then handbrake to convert (using the iPad preset, but use what you like). I only ever need ffmpeg to rotate 90 degrees because handbrake can flip and reverse. I trash the input files rather than delete them - I have another hazel rule that clears this out when they get old - just in case I need to recover them.
I have a .cli directory in my home folder that contains HandbrakeCLI and ffmpeg (which includes ffprobe). Also I have a directory called .scratch in the home folder to put the rotated video.
My hazel rule renames ignores all files called *.i.mov and the first thing I do is find all *.mov files and rename them to *.i.mov, then run this script.
Hope this is useful.
I was looking for this for a while and didn't find it, so I hope it's useful to someone here.
I use dropbox to automatically upload my iPhone videos and pictures and have a desktop machine with hazel that fixes the rotation and then converts (and compresses) to m4v.
Anyway, the guts of it is in a script that I call that looks something like this:
- Code: Select all
export PATH=$PATH:~/.scripts:~/.cli
in="$1"
tmp="$HOME/.scratch/`date +%s`.r.mov"
flip=""
rotate='ffmpeg -nostdin -i "$1" -vf transpose=1 "$tmp"'
orient=$(ffprobe "$1" 2>&1 | grep rotate)
if [[ "$orient" == *90* ]]
then
eval $rotate
in="$tmp"
elif [[ "$orient" == *270* ]]
then
eval $rotate
in="$tmp"
flip="--rotate"
elif [[ "$orient" == *180* ]]
then
flip="--rotate"
fi
HandbrakeCLI -i "$in" -o "${1%.*}".m4v --preset="iPad" $flip
mv "$tmp" ~/.Trash
mv "$1" ~/.Trash
Basically I used ffprobe to determine if it needs rotating. If it does I use ffmpeg to do it, then handbrake to convert (using the iPad preset, but use what you like). I only ever need ffmpeg to rotate 90 degrees because handbrake can flip and reverse. I trash the input files rather than delete them - I have another hazel rule that clears this out when they get old - just in case I need to recover them.
I have a .cli directory in my home folder that contains HandbrakeCLI and ffmpeg (which includes ffprobe). Also I have a directory called .scratch in the home folder to put the rotated video.
My hazel rule renames ignores all files called *.i.mov and the first thing I do is find all *.mov files and rename them to *.i.mov, then run this script.
Hope this is useful.