Created
August 8, 2016 21:33
-
-
Save ViktorNova/1dd68a2ec99781fd9adca49507c73ee2 to your computer and use it in GitHub Desktop.
Rotate a video with FFmpeg (100% lossless, and quick)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$INPUTVIDEO='input.mp4' | |
$OUTPUTVIDEO='output.mp4' | |
ffmpeg -i $INPUTVIDEO -metadata:s:v rotate="-90" -codec copy $OUTPUTVIDEO |
I had success with this
ffmpeg -i input.mp4 -vf "transpose=1" output.mp4
This link explains the correct way to do it now (without reencoding), as the -metadata:s:v rotate="-90"
method has been deprecated and removed from the most recent versions of ffmpeg.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had no luck with this when using mplayer or a server's html5 player to play a video encoded on an iphone in portrait mode. Both the original clip, and the clip encoded using ffmpeg with the 'rotate="90"', displayed video rotated -90 degrees (top of the picture on the left)
This is likely related to how iphones rotate clips: the material is always encoded with width greater than height; the track header, or "tkhd", for the video track indicates width=1920 and height=1080 for this portrait-recorded clip. Apple attempts to signal rotation to the decoder (in this case mplayer or the html5 player) by using the "matrix" values in the "tkhd" to indicate that the decoder must rotate the video by 90 degrees. This clip uses a matrix which does that, rather than a unity matrix that would indicate no rotation.
However, the international standard for the video (ISO/IEC 14496-12 2015, section 8.3.2.3) indicates that the "matrix" values must be a unity matrix ...
In other words, ISO (International Standards Organization) does not allow the encoder to use the matrix for the rotation. Because of that, an ISO-compliant decoder can ignore the video rotation. Players may optionally support it (ffplay does), at the expense of computation complexity (cpu cycles).
I've dealt with this issue in web servers by always fully transcoding any video that's uploaded, using ffmpeg (which, like ffplay, is based on libavformat, which provides the rotation). This resets the tkhd matrix to a unity matrix.