video captured from iphone gets rotated when conve

2019-01-13 06:19发布

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 problem is that when I shoot the video (in portrait orientation) and it is converted (using ffmpeg) and then played back from the server, it appears to be rotated. Any idea?

9条回答
倾城 Initia
2楼-- · 2019-01-13 07:00

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
查看更多
女痞
3楼-- · 2019-01-13 07:02

What you can also do is remove the QuickTime specific metadata when rotate the .mov. This will make sure that the video is rotated the same way in VLC and QuickTime

ffmpeg -i in.mov -vf "transpose=1" -metadata:s:v:0 rotate=0 out.mov

Here's the documentation on the -metadata option (from http://ffmpeg.org/ffmpeg.html):

-metadata[:metadata_specifier] key=value (output,per-metadata)

Set a metadata key/value pair.

An optional metadata_specifier may be given to set metadata on streams or chapters. See -map_metadata documentation for details.

This option overrides metadata set with -map_metadata. It is also possible to delete metadata by using an empty value.

For example, for setting the title in the output file:

 ffmpeg -i in.avi -metadata title="my title" out.flv 

To set the language of the first audio stream:

 ffmpeg -i INPUT -metadata:s:a:1 language=eng OUTPUT
查看更多
Viruses.
4楼-- · 2019-01-13 07:03

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.

查看更多
登录 后发表回答