Tool

Video Rotation Flag Checker and Patcher

Some videos look fine in one program but lie on their side or show up upside down in another. In these videos the picture itself is not rotated. The file just carries a note saying “display this turned by so many degrees,” and players often differ in whether they follow that note. Pick a file and this tool reads the note, tells you what it says, and creates a new file with only the note changed to the orientation you want. The video is not re-encoded and the file never leaves this browser.

Where is the rotation flag in the file?

In MP4 and MOV, each video track has a tkhd (track header) box, and inside it sits a 3×3 transform matrix stored as 36 bytes (nine 32-bit integers). Rotation is written in the upper-left 2×2 values of this matrix (a, b, c, d). With no rotation, a and d are 1 (00010000 in 16.16 fixed point) and b and c are 0; a 90° clockwise rotation is a=0, b=1, c=−1, d=0. These are exactly the values this tool reads and writes. The structure is separate from mdat, which holds the video, so changing the matrix does not alter a single byte of the compressed video data.

Phones are known to have a sensor fixed in landscape, so even when you shoot in portrait they store a landscape frame and attach a rotation note to it. That is why the same file shows up upright in a player that follows the note and on its side in one that ignores it.

What this tool does

  • Read: It reads only the moov header and interprets the matrix of each video track. If it matches exactly 0, 90, 180 or 270° it shows the angle; if a flip is mixed in or the matrix is not a multiple of 90°, it tells you so. It never reads the video data, so even large files finish quickly.
  • Patch: Choose the orientation you want (clockwise) and it lets you download a new file in which the 36-byte matrix of every video track is replaced with that value. Because the number of bytes changed and the file length are the same, the positions of other boxes and the offset tables stay valid. The original is left as is.
  • Commands: It generates an ffmpeg command that gives the same result and an ffprobe command for checking.

How to use it

  1. Pick the file that plays sideways and look at the “rotation flag” value.
  2. If the value is 0°, the note says “do not rotate,” so every player shows the stored frame as is. If it still looks on its side, the frame itself was stored on its side, and you can fix it by changing the flag to 90° or 270° and trying it out.If the value is 90° or 270°, the picture may be correct in apps that follow the flag and on its side in apps that ignore it. In that case, changing the flag to 0° leaves the screen of the ignoring app unchanged and makes the following apps show it on its side instead, so to get it right everywhere you have to rotate the frames themselves by re-encoding.
  3. Choose the orientation that should appear on screen, measured clockwise, and save. If it comes out turned the wrong way, pick the value 180° away (for example 270 instead of 90).
  4. Drop the saved file back into this tool to check that the value changed, and check in the player that had the problem that the orientation is now right.
  5. If you suspect the MP4 structure itself is odd, use the MP4 box structure inspector; to see resolution and codec in one go, use the video file info inspector. For vertical videos meant for Shorts there is also the Shorts vertical video checker.

Doing it with ffmpeg

Recent versions of ffmpeg have an input option, -display_rotation. The official description is “the angle in degrees to rotate the video counterclockwise before display,” and it overrides the rotation information already in the file. Because it is an input option it must come before -i; there are reports that putting it after causes an error. Used together with -c copy, the video is not re-encoded. The command this tool generates converts the clockwise value above into the counterclockwise value.

ffmpeg -display_rotation 270 -i input.mp4 -c copy output.mp4

The -metadata:s:v rotate=90 method that appears in many older posts was marked for deprecation in a 2022 development list together with the addition of -display_rotation, and there is also an issue report saying it does not work in recent builds (FFmpeg ticket #10684). This site has not checked from which version it stopped working, so if a command from an old post does not take effect, use the approach above. A filter such as -vf transpose=1 rotates the picture itself, so it needs re-encoding and causes generation loss. If fixing only the flag is enough, you do not need it.

Limits worth knowing

  • Behavior in individual players was not tested. It is known that some players and editors ignore the rotation flag, but this site has not checked in a table how each app handles it. If the flag is right and the video still shows up on its side, that app may be ignoring the flag, and then you have to rotate the picture itself by re-encoding.
  • The width and height values in tkhd are not changed. As far as we know, ffmpeg's -display_rotation also changes only the matrix, so this tool does the same, but how the result looks in tools that consult the width and height values was not checked.
  • Rotation information stored elsewhere is not read. Orientation information inside the video bitstream, the separate metadata entry used in older files, and the matrix in the movie-level header (mvhd) are not handled.
  • Flips and arbitrary transforms are not supported. If a mirror flip is mixed in, the tool can read it, but patching removes the flip and leaves only the rotation you selected.
  • MKV and WebM cannot be read. MKV is known to store rotation information in a different way, and this tool handles only the MP4 family. For MKV, first look at wrapping it with the MKV to MP4 converter.
  • The parser is this site's own implementation and has not been verified against files from many devices and authoring tools. Always open the saved file and check it before using it for anything important. This site does not send the file or its name to a server.