Page 1 of 1

Compress and fix rotation of iPhone videos

PostPosted: 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.

Re: Compress and fix rotation of iPhone videos

PostPosted: Fri Jan 24, 2014 7:29 pm
by Oo0Bailey0oO
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!

Re: Compress and fix rotation of iPhone videos

PostPosted: Mon May 19, 2014 4:02 pm
by yendi
Deleted

Re: Compress and fix rotation of iPhone videos

PostPosted: 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

Re: Compress and fix rotation of iPhone videos

PostPosted: Thu Oct 16, 2014 1:15 am
by David70
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:

Re: Compress and fix rotation of iPhone videos

PostPosted: Thu Oct 16, 2014 1:23 am
by tmcalvin
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.

Re: Compress and fix rotation of iPhone videos

PostPosted: Thu Feb 19, 2015 6:46 am
by shahjahan
Use this code
HandbrakeCLI -i "$in" -o "${1%.*}".m4v --preset="iPad" $flip

after flip art function ();