Compress and fix rotation of iPhone videos

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

Compress and fix rotation of iPhone videos Fri Dec 13, 2013 8:07 pm • by njorogle
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:

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.
njorogle
 
Posts: 6
Joined: Fri Dec 13, 2013 7:54 pm

Hi,

Thank you very much for posting this. This is exactly what I was looking for.

The only thing I'd like to do but couldn't figure out is to move the resulting file to a different folder. I tried by sticking a prefix path on the HandbrakeCLI destination (e.g. "/path/${1%.*}") and then I tried a Hazel rule after the conversion step, but neither worked.

It's very minor, but any tips on that?

Thanks again!
Oo0Bailey0oO
 
Posts: 1
Joined: Fri Jan 24, 2014 1:47 am

Re: Compress and fix rotation of iPhone videos Mon May 19, 2014 4:02 pm • by yendi
Deleted
Last edited by yendi on Wed Jun 18, 2014 2:35 pm, edited 1 time in total.
yendi
 
Posts: 5
Joined: Thu May 01, 2014 6:35 am

Re: Compress and fix rotation of iPhone videos Wed Jun 18, 2014 2:35 pm • by yendi
Hi again!

I tried the script but it actually do not rotate the videos:
I watched the .scratch folder and files are not passed to that directory: video stays where they are, are processed there and then the original is sent to trash...
What am I missing??

Edit:
Apparently the command line differs from a compilation to an other
Depending on which version of ffmpeg you have and how it's compiled, one of the following should work...

ffmpeg -vfilters "rotate=90" -i input.mov output.mp4
...or...

ffmpeg -vf "transpose=1" -i input.mov output.mp4


http://stackoverflow.com/questions/9408 ... 94#9409094

Would you mind sharing your ffmpeg binary please?

Thanks
yendi
 
Posts: 5
Joined: Thu May 01, 2014 6:35 am

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. :lol:
Unlike scam brain dumps dumps and SAP dumps training program.
David70
 
Posts: 1
Joined: Thu Oct 16, 2014 1:14 am

David70 wrote: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. :lol:


I have a similar setup using dropbox. Would you mind sharing your rotation/conversion scripts? I've been racking my brain trying to make this work the past few days.
Would be much appreciated.
tmcalvin
 
Posts: 1
Joined: Thu Oct 16, 2014 1:20 am

Use this code
HandbrakeCLI -i "$in" -o "${1%.*}".m4v --preset="iPad" $flip

after flip art function ();
shahjahan
 
Posts: 1
Joined: Thu Feb 19, 2015 6:33 am


Return to Tips & Tricks - DO NOT POST QUESTIONS