6

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.

9

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.

| improve this answer | |
  • 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
1

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

| improve this answer | |

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.