Rotate a video with FFmpeg

Use -vf transpose=1 to turn the picture 90 degrees clockwise, or transpose=2 for counterclockwise. That re-encodes. To rotate instantly, keep the pixels and set the rotation flag players read. Put -display_rotation -90 before -i and add -c copy.

Re-encode Re-encode

The rotation must hold in every player, editor and upload pipeline.

ffmpeg -i in.mp4 -vf transpose=1 -c:a copy out.mp4

546x1280. The pixels are turned, so every player and editor shows it upright.

Size out
546x1280
Rotation flag
none
Run time
952 ms
Output
2.9 MB
Instant Stream copy

You want it fast and lossless, and the file plays in a player that reads the flag.

ffmpeg -display_rotation -90 -i in.mp4 -c copy out.mp4

Still 1280x546 inside, with a rotation of -90 in the header. Chrome played it as 546x1280, turned clockwise.

Pixels
1280x546, untouched
Chrome shows
546x1280
Run time
84 ms
Output
6.4 MB

Proof

One frame, every direction

Frame 48 of each output, 2 s in, fitted on a dark canvas. The last two pictures are the phone clip, as stored and as FFmpeg re-encodes it.
in.mp4
The input frame, the girl upright on the left, a stone wall on the right
1280x546 The input, for reference. The girl is on the left, the roof on the right.
transpose=1 90 degrees clockwise
The frame turned 90 degrees clockwise, the girl at the top with her head pointing right
546x1280 The left edge is now the top. -display_rotation -90 displays the same way.
transpose=2 90 degrees counterclockwise
The frame turned 90 degrees counterclockwise, the girl at the bottom with her head pointing left
546x1280 The left edge is now the bottom.
hflip,vflip 180 degrees
The frame upside down, the girl on the right
1280x546 Two flips make a half turn. It matched transpose=1,transpose=1 pixel for pixel.
phone.mp4, -noautorotate What is in the file
The phone clip as stored, the girl's face lying on its side
960x540 The pixels lie on their side. Only the -90 flag makes players show it upright.
ffmpeg -i phone.mp4 out.mp4 Upright, no flag needed
The phone clip upright after a plain re-encode
540x960 FFmpeg applied the flag while decoding, so the new file has upright pixels and no flag.

Footage: Sintel, © Blender Foundation, CC BY 3.0.

Run it

Run it on Rendobar

Send the same command from your code. The job fetches each input from its URL and returns the output file's URL when it finishes.

job.ts
import { createClient } from "@rendobar/sdk";
const rb = createClient({ apiKey: process.env.RENDOBAR_API_KEY });
const job = await rb.jobs.run({
type: "ffmpeg",
inputs: {
"in.mp4": "https://cdn.rendobar.com/examples/rotate-video/in.mp4",
},
params: {
command: "ffmpeg -i in.mp4 -vf transpose=1 -c:a copy out.mp4",
},
});
console.log(job.output.file.url);

Install with npm i @rendobar/sdk. jobs.run() submits and waits, so it returns the finished job in one call.

terminal
curl https://api.rendobar.com/jobs \
-H "Authorization: Bearer $RENDOBAR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "ffmpeg",
"inputs": {
"in.mp4": "https://cdn.rendobar.com/examples/rotate-video/in.mp4"
},
"params": {
"command": "ffmpeg -i in.mp4 -vf transpose=1 -c:a copy out.mp4"
}
}'

Returns immediately with a job id. Poll GET /jobs/{id} or register a webhook rather than blocking on the request.

Every variant

Pick the command for your case

Each one ran on the same input. The line under it is what came out. Run times are the best of three runs with FFmpeg 8.0 on one desktop machine, so read them as relative.

  1. Rotate 90 degrees counterclockwise

    Re-encode
    ffmpeg -i in.mp4 -vf transpose=2 -c:a copy out.mp4

    546x1280, the left edge now at the bottom.

    934 ms run 2.9 MB 10.00 s long

  2. Rotate 180 degrees, upside down

    Re-encode
    ffmpeg -i in.mp4 -vf hflip,vflip -c:a copy out.mp4

    1280x546, upside down. The same pixels as transpose=1,transpose=1.

    1.0 s run 2.9 MB 10.00 s long

  3. Flip horizontally, mirror image

    Re-encode
    ffmpeg -i in.mp4 -vf hflip -c:a copy out.mp4

    1280x546, left and right swapped. Use vflip to flip top to bottom.

    1.0 s run 3.7 MB 10.00 s long

  4. Fix a sideways phone video for good

    Re-encode
    ffmpeg -i phone.mp4 -c:a copy out.mp4

    540x960 upright pixels and no rotation flag. No filter needed, FFmpeg applies the flag when it decodes.

    800 ms run 2.7 MB 10.00 s long

  5. Remove the rotation flag

    Stream copy
    ffmpeg -display_rotation 0 -i phone.mp4 -c copy out.mp4

    Same bytes of video, flag gone. Chrome played it 960x540, lying on its side, which is what the pixels hold.

    80 ms run 4.3 MB 10.00 s long

  6. Rotate by any angle

    Re-encode
    ffmpeg -i in.mp4 -vf rotate=10*PI/180 -c:a copy out.mp4

    1280x546, tilted 10 degrees clockwise. The frame size stays, so the corners are cut and filled black.

    1.2 s run 2.9 MB 10.00 s long

Gotchas

Where it goes wrong

Which transpose value do I need?

Four values, checked pixel for pixel on the test clip:

  • transpose=1: 90 degrees clockwise.
  • transpose=2: 90 degrees counterclockwise.
  • transpose=0: counterclockwise and flipped top to bottom, the same as transpose=2,vflip.
  • transpose=3: clockwise and flipped top to bottom, the same as transpose=1,vflip.

There is no value for 180. Use hflip,vflip or transpose=1,transpose=1, which gave identical pixels. The names clock and cclock work in place of 1 and 2.

How do I rotate without re-encoding?

Write a rotation flag and copy the streams. -display_rotation goes before -i, and it counts counterclockwise, so clockwise is negative:

ffmpeg -display_rotation -90 -i in.mp4 -c copy out.mp4

ffprobe showed the pixels still 1280x546 with rotation=-90. Chrome played it 546x1280, and FFmpeg decoded it to the same picture as transpose=1.

The old way, still in most answers online, does nothing on FFmpeg 8.0:

ffmpeg -i in.mp4 -c copy -metadata:s:v rotate=90 out.mp4

No rotation in the output. ffprobe found no display matrix and Chrome played it landscape, unchanged.

A flag only works where something reads it. If a tool shows your file sideways, re-encode with transpose so the pixels themselves are turned.

Why is my phone video rotated twice?

Phones store portrait video on its side and add a rotation flag. When FFmpeg re-encodes, it applies the flag first, so the frames reaching your filters are already upright. Adding a transpose on top turns them again:

ffmpeg -i phone.mp4 -vf transpose=1 -c:a copy out.mp4

960x540, lying on its side. The clip was already 540x960 upright before transpose ran.

For a phone video that only looks wrong in one tool, a plain re-encode with no filter fixes it, as in the task above. To filter the stored pixels instead of the upright picture, put -noautorotate before -i.

Related: Crop a video, Resize a video, Strip metadata.

Your command. Our infrastructure.

Bring your own commands. Run them on scalable CPU and GPU infrastructure, and pay only for compute time.