Compress and Rotate Videos

For easier and faster viewing of videos online, I compress them before uploading to my server. My goto application for this is HandBrake. It’s cross-platform, has lots of options as well as easy presets, does a really good job of compressing, and is open source.

The two options HandBrake is seemingly missing that I’ve been wanting.. batch and rotate. It does have a queue that can be processed, but all things added to the queue are done so manually. And no rotate. However.. HandBrakeCLI DOES have these options. Because of course its CLI you can script to to do batch, and they’ve added a rotate feature.

The rotate is a little funky and not documented so well though. From various forums it seems that the options are:

  • 1 = flip X axis
  • 2 = flip Y axis
  • 3 = flip on X & Y axes (180 degree rotate)
  • 4 = flip? (anyway this does a 90 degree rotate)

So the command I used was:

HandBrakeCLI -i vid_file.mov -o vid_file.mp4 –preset=”Android”, –rotate=4

Then I scripted the process for the entire directory.

for FILE in `ls`; do HandBrakeCLI -i $FILE -o ../export/`echo $FILE | cut -d”.” -f1`.mp4 –preset=”Android”, –rotate=4; done

Cool. I’ll be bypassing the GUI and using the CLI from now on.