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

后端 未结 10 1768
名媛妹妹
名媛妹妹 2020-12-01 02:31

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 pr

相关标签:
10条回答
  • 2020-12-01 02:59

    I've filmed the video with Ipad3 and it was oriented upside down, which I suppose is the common situation of all Apple devices at some versions. Besides of it, the 3-minutes long MOV file (1920x1090) took about 500 Mb in size, which made it not available to share easily. I had to convert it to MP4, and analyzing all threads I've found on stackoverflow, here's the final code string for ffmpeg I've used (ffmpeg ver. 2.8.4):

    ffmpeg -i IN.MOV -s 960x540 -metadata:s:v rotate="0" -acodec libmp3lame OUT.mp4
    

    I suppose you may just leave '-metadata:s:v rotate="0"' if you don't need the resize and audio codec change. Note that if you resize the video, width and height should fully divide to 4.

    0 讨论(0)
  • 2020-12-01 03:01

    Depending on which version of ffmpeg you have and how it's compiled, one of the following should work...

    ffmpeg -vfilters "rotate=90" -i input.mov output.mp4
    

    ...or...

    ffmpeg -vf "transpose=1" -i input.mov output.mp4
    
    0 讨论(0)
  • 2020-12-01 03:04

    Or... to simply change the tag in an existing file:

    Read the current rotation

    exiftool -Rotation <file>
    

    then, for example:

    exiftool -Rotation=180 <file>
    

    to set it to 180

    0 讨论(0)
  • 2020-12-01 03:07

    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.

    0 讨论(0)
提交回复
热议问题