Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set rotation field for a video stream with FFmpeg?

I have a video file. I open it with MediaInfo utility and I can see a video stream in this file having attribute Rotation 90 (along with other attributes such as CodecID, bitrate etc).

Now I have another video file which does not have that attribute Rotation 90, it does not have the Rotation attribute at all.

Can I use ffmpeg.exe so that it produces output file with Rotation 90 attribute added and with no other changes? I don't really want to do any transform, just want to set the Rotation attribute.

I've tried the -metadata option to no avail.

like image 962
Alexander Kulyakhtin Avatar asked Mar 11 '13 09:03

Alexander Kulyakhtin


People also ask

How do I rotate an image in FFmpeg?

FFMpeg has a feature called "Transpose" that is used to rotate videos. Using this feature, we can easily rotate videos clockwise and counter-clockwise as well as flip them vertically and horizontally. Here, transpose=1 parameter instructs FFMpeg to transposition the given video by 90 degrees clockwise.


1 Answers

This works with recent FFmpeg:

ffmpeg -i input.mp4 -c copy -metadata:s:v:0 rotate=90 output.mp4 

This will stream copy the bitstreams, so no encoding is performed. Only the metadata of the first video stream (v:0) is changed here and the player will show the video in a rotated way. (Not all players will support this.)

Additional notes:

  • If you want to "physically" rotate the video, you have to use the transpose filter. Filtering will require re-encoding, so you will have to remove -c copy.

  • If you omit -c copy, and want to encode instead of only re-muxing, then ffmpeg will automatically rotate the video if there is any existing rotate metadata. You can disable this behavior with -noautorotate.

like image 72
slhck Avatar answered Oct 05 '22 17:10

slhck