Rotating and Flipping Video — transpose Filter vs. Metadata Rotation

There are many cases where a video shot vertically on a smartphone appears sideways, or you simply need to rotate a video 90 degrees. This article explains how to rotate and flip video using FFmpeg 6.1.


transpose Filter Values and Effects

The transpose filter rotates video in 90-degree increments. The direction of rotation differs by value.

ValueTransformation
090° counter-clockwise + vertical flip (cclock_flip)
190° clockwise (clock)
290° counter-clockwise (cclock)
390° clockwise + vertical flip (clock_flip)

You can also use the aliases clock, cclock, clock_flip, and cclock_flip instead of numbers.


90° Clockwise (Most Common Case for Fixing Portrait Video)

ffmpeg -i input.mp4 -vf transpose=1 output.mp4

If a video shot in portrait mode on a smartphone appears sideways in a player, this command will fix it in most cases.


90° Counter-Clockwise

ffmpeg -i input.mp4 -vf transpose=2 output.mp4

transpose=2 can also be written as transpose=cclock.


180° Rotation

Chain transpose twice to achieve a 180° rotation.

ffmpeg -i input.mp4 -vf transpose=1,transpose=1 output.mp4

Or combining hflip and vflip produces the same result:

ffmpeg -i input.mp4 -vf "hflip,vflip" output.mp4

hflip — Horizontal Flip (Left-Right Mirror)

ffmpeg -i input.mp4 -vf hflip output.mp4

Mirrors the image left to right. Useful for flipping selfie videos or creating mirror effects.


vflip — Vertical Flip (Top-Bottom Mirror)

ffmpeg -i input.mp4 -vf vflip output.mp4

Flips the image upside down. Used to fix videos that were accidentally recorded upside down.


Metadata Rotation vs. Re-encoding Rotation

Video rotation information is recorded in two ways.

Metadata Rotation (displaymatrix / rotate tag)

This method records the rotation angle in the container metadata. The video pixels themselves are not changed — it simply instructs the player to display the video rotated.

Advantages: Fast with no re-encoding, no quality loss
Disadvantages: Will not display correctly in players that ignore metadata (older players, some video editing software)

To remove the rotation tag from metadata (= remove the rotation instruction to the player):

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

This command only modifies metadata without re-encoding. Shown as a text block since metadata verification is difficult in CI test environments.

Re-encoding Rotation (transpose filter)

Using the transpose filter actually rotates the video pixels themselves and writes out a new video.

Advantages: Displays correctly in any player, no metadata dependency
Disadvantages: Requires re-encoding (takes time), slight quality change from encoding


Fixing Rotation for Smartphone-Recorded Video

Videos shot in portrait mode on iPhone or Android typically have rotate=90 recorded in metadata. They display correctly in compatible players, but can appear sideways when imported into editing software.

How to check (inspect rotation metadata with ffprobe):

ffprobe -v error -select_streams v:0 -show_entries stream_tags=rotate -of default=nw=1 input.mp4

Normalize the video by respecting the rotation metadata (re-encode):

ffmpeg -i input.mp4 -vf transpose=1 output.mp4

If the metadata rotation value is 90, apply transpose=1 (90° clockwise).

To auto-detect and apply rotation:

Since FFmpeg 5.0, the -vf autorotate filter is available (may be experimental). You can also disable automatic rotation application with the -noautorotate option.


Combining Multiple Filters

To apply rotation and resize or other filters simultaneously, chain them with commas:

ffmpeg -i input.mp4 -vf "transpose=1,scale=1280:720" output.mp4

Applying transpose first means scale is applied to the post-rotation dimensions. Pay attention to the order.


Summary

PurposeCommand
90° clockwise-vf transpose=1
90° counter-clockwise-vf transpose=2
180°-vf transpose=1,transpose=1
Horizontal flip-vf hflip
Vertical flip-vf vflip
Metadata-only fix-c copy -metadata:s:v:0 rotate=0

Choose the metadata method when you want to avoid re-encoding, or choose transpose filter re-encoding when reliable display is the priority.

Related articles:


Tested with: ffmpeg 6.1.1 / Ubuntu 24.04 (GitHub Actions runner)
Primary sources: ffmpeg.org/ffmpeg-filters.html / ffmpeg.org/ffmpeg.html / trac.ffmpeg.org/wiki/RotateVideo