Change Video Rotation Metadata in FFmpeg

Rotating a video by re-encoding its physical pixels is a slow, CPU-heavy process that can degrade video quality. This article explains how to instantly change a video's orientation (such as rotating it 90, 180, or 270 degrees) using FFmpeg by modifying only its metadata, leaving the underlying video stream untouched and preserving original quality.

The FFmpeg Command for Metadata Rotation

To rotate a video using metadata, you use the stream metadata option (-metadata:s:v) combined with the stream copy flag (-c copy). This tells FFmpeg to write the rotation instruction into the file header and copy the video data without re-encoding it.

Run the following command in your terminal:

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

Command Breakdown

  • -i input.mp4: Specifies the path to your source video file.
  • -metadata:s:v rotate="90": Targets the metadata of the video stream (s:v) and sets the rotate tag. You can set this value to 90, 180, 270, or 0 (to reset the rotation).
  • -c copy: Tells FFmpeg to copy both the video and audio streams directly. Since no re-encoding occurs, the process takes only a fraction of a second.
  • output.mp4: The name of the newly generated video file.

How to Reset or Clear Rotation Metadata

If a video plays sideways because of an incorrect rotation tag, you can reset the rotation metadata to zero with this command:

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

Important Considerations

  • Player Compatibility: This method relies on the media player reading and respecting the rotation metadata tag. While modern players like VLC, QuickTime, MX Player, and most web browsers support this tag, some older players or legacy hardware may ignore it and display the video in its original, unrotated state.
  • Container Support: Metadata rotation is widely supported in MP4, MOV, and MKV formats. If your source video is in a different format, you may need to output it to MP4 or MOV for the metadata tag to write correctly.