Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

migrated from stackoverflow.com Mar 11 '13 at 16:37

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

1 Answer

up vote 4 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 portrait.mov \
-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.

  • Check out the x264 encoding guide for more.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.