How to Set Video Rotation Metadata in FFmpeg

This article explains how to quickly change or set a video's rotation metadata (such as 90, 180, or 270 degrees) using FFmpeg without re-encoding the video stream. By modifying only the metadata, you can change the playback orientation instantly while preserving the original video quality and saving CPU resources.

To set the rotation metadata without altering the actual video frames, you must use the stream copy mode (-c copy) along with the metadata flag targeted at the video stream (-metadata:s:v).

The FFmpeg Command

Run the following command in your terminal to set the rotation metadata to 270 degrees:

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

Command Breakdown

  • -i input.mp4: Specifies the path to your source video file.
  • -c copy: Instructs FFmpeg to copy both the video and audio streams directly to the output file without re-encoding (transcoding) them. This makes the process nearly instantaneous.
  • -metadata:s:v rotate="270": Targets the video stream (s:v) and sets its rotate metadata tag to 270 degrees. You can replace 270 with other standard rotation values like 90 or 180.
  • output.mp4: The name of the newly generated video file containing the updated metadata.

How to Reset or Clear Rotation Metadata

If you want to clear the rotation flag so the video plays in its default native orientation, set the rotation value to 0:

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

Important Considerations

  • Player Compatibility: This method relies on the media player to read the rotation metadata flag and rotate the video during playback. Most modern media players (such as VLC, QuickTime, MX Player, and modern web browsers) support this flag.
  • Hardware Players: Some older hardware-based media players or legacy TVs may ignore metadata flags and play the video in its original unrotated orientation. If compatibility with legacy devices is required, you must instead physically rotate the frames, which requires re-encoding using video filters (e.g., -vf "transpose=2").