Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am recording videos on iPhone and uploading them to my Linux server. Users can see these videos on website. If users are seeing videos on mac or iDevices the video is looking fine but when users are seeing that video on windows systems these videos are getting rotated.

I am assuming this is because of some apple's flag in the recorded video which Windows systems are not able to read. Can I record videos in some way so they don't get rotated on Windows systems? Or is there any way I can re-encode videos with proper interface orientation using FFmpeg?

I am open to both FFmpeg or iOS way.

share|improve this question

migrated from Mar 11 '13 at 16:37

This question came from our site for professional and enthusiast programmers.

up vote 6 down vote accepted

You can't change the way the iOS camera records video. It sets a rotation flag, and if you want the video to be shown correctly in both OS X and Windows (and other players), you'll have to:

  • Remove the rotation flag. Now your video is landscape, but still showing wrong.
  • Re-encode the video, rotating it.

Download ffmpeg (a static build for your OS is fine).

You then need the transpose filter, e.g.

ffmpeg -i \
-c:v libx264 -filter:v "transpose=1" \
-c:a copy \
-metadata:s:v:0 rotate=0 out.mp4

A few remarks:

  • Here, transpose=1 will rotate by 90°. If your video is upside down, you need to combine the options. You can either use -filter:v "transpose=2,transpose=2" or others. See here: How to flip a video 180° (vertical/upside down) with FFmpeg?

  • The -metadata:s:v:0 rotate=0 option ensures that the rotation metadata in the first video stream is set to 0 again (it was on 90 before), so your video now shows fine on both OS X and other OSes.

  • Naturally, transposing will re-encode the video and you'll lose quality. Add the -crf option after -c:v libx264 to set the Constant Rate Factor, which controls the quality. Use lower values to get better quality. 23 is actually the default, so you don't need to specify it at all, but you might want choose something as low as 18 if the video ends up looking bad otherwise, e.g., -c:v libx264 -crf 18.

  • In some cases you might just want to remove the rotation flag but keep the original video bitstream intact. To do so, replace -c:v libx264 -filter:v "transpose=1" with -c:v copy.

  • Check out the x264 encoding guide for more.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .