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.


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.

  • 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.

  • On every iPhone I've owned, the "native" orientation for the rear-facing camera is with the phone in landscape orientation, with the camera lens toward the left hand. If the video was originally shot in that orientation, stripping the rotation flag without re-encoding should be enough. (Although it would probably show correctly in all players without modification anyway.)
    – smitelli
    Jul 22 '18 at 1:40

Download and Install AviDemux.

Open your video in there and choose:

Video Output = Copy
Audio Output = Copy
Output Format = MP4 Muxer
Configure = Rotate Video 270°

and finally File > Save the new rotated video.

Avidemux setup



Often phones record videos rotated, but then add some rotational metadata for media players to read to then rotate them for viewing.

Windows 7's Windows Media Player ignores rotational metadata.

Windows 10's windows media player obeys rotational metadata.

ffplay has an option -autorotate or -noautorotate https://ffmpeg.org/ffplay.html So with that you can see clearly the difference.

the command's ffmpeg and mediainfo (which can be installed on windows), can show rotational metadata.

If you do ffmpeg -i blah.mp4 -acodec libmp3lame -vcodec libx264 blah2.mp4 that will re-encode the video rotating it obeying rotational metadata, and remove any rotational metadata from the output.

So any video that shows up rotated (by a media player that disregards rotational metadata), will be fixed. So that all media players will play it with the correct orientation.

It really is as simple as that..

Before I knew that I was using ffmpeg to first remove rotational metadata, if any existed, then re-encode the video rotated.. based on what the rotational metadata was.. It was a mess.

But then I found out that just the most simple standard ffmpeg command, mentioned, a regular re-encoding, does the same result as that, it encodes the video taking into account rotational metadata and removing rotational metadata from the output!

So you can copy all the videos off your "phone" into some directory, then make a directory within that called e.g. "a", then do for %f in (*.mp4) do @echo ffmpeg -i -acodec libmp3lame -vcodec libx264 a\%f And then without that subdirectory called "a", ffmpeg will put all the mp4 files fixed for you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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