video captured from iphone gets rotated when converted to .mp4 using ffmpeg

aqs picture aqs · Feb 23, 2012 · Viewed 32.3k times · Source

When I try to upload videos captured from my iPhone in my app, the server performs a conversion from .mov to .mp4 so that it can be played in other platforms. However the problem is that when I shoot the video (in portrait orientation) and it is converted (using ffmpeg) and then played back from the server, it appears to be rotated. Any idea?

Answer

Albin picture Albin · Jun 17, 2015

FFMPEG changed the default behavior to auto rotate video sources with rotation metadata in 2015. This was released as v2.7.

If your ffmpeg version is v2.7 or newer, but your rotation metadata isn't respected, the problem is likely that you are using custom rotation based on metadata. This will cause the same logic to be applied twice, changing or cancelling out the rotation.

In addition to removing your custom rotation (recommended), there's an option to turn off auto rotation with -noautorotate.

ffmpeg -noautorotate -i input.mp4...

This will also work in some older releases.