How to Rotate Video with FFmpeg (CLI + API Guide)

Mobile phones shoot vertical video. Webcams sometimes lie about orientation. User-uploaded content arrives sideways. If you're processing video in a pipeline, rotation bugs will find you.
FFmpeg handles rotation with the transpose filter. One flag, four directions. But the gotchas around metadata, audio streams, and container formats trip up even experienced developers. This guide covers the CLI commands, the common pitfalls, and how to do it all through an API if you don't want FFmpeg on your server.
The transpose filter: 90, 180, and 270 degrees
FFmpeg's transpose filter re-encodes the video with rotated pixel data. It actually moves pixels, not just sets a metadata flag.
90 degrees clockwise:
ffmpeg -i input.mp4 -vf "transpose=1" -c:a copy output.mp4
90 degrees counter-clockwise:
ffmpeg -i input.mp4 -vf "transpose=2" -c:a copy output.mp4
180 degrees (upside down):
There's no single transpose value for 180. Chain two rotations:
ffmpeg -i input.mp4 -vf "transpose=1,transpose=1" -c:a copy output.mp4
Or use hflip and vflip together, which is slightly faster since it doesn't involve a full transpose:
ffmpeg -i input.mp4 -vf "hflip,vflip" -c:a copy output.mp4
All four transpose values:
| Value | Direction | Output dimensions |
|---|---|---|
| 0 | 90° counter-clockwise + vertical flip | Swapped |
| 1 | 90° clockwise | Swapped |
| 2 | 90° counter-clockwise | Swapped |
| 3 | 90° clockwise + vertical flip | Swapped |
The -c:a copy flag passes audio through untouched. Without it, FFmpeg re-encodes audio too, which wastes time and can degrade quality.
Metadata rotation vs re-encoding
Some videos look rotated in a player but the actual pixel data is fine. The rotation is stored as a flag in the container (the display matrix in MP4/MOV files). iPhones do this constantly.
Check for a rotation flag with ffprobe:
ffprobe -v error -select_streams v:0 -show_entries stream_side_data=rotation -of default=nw=1 input.mp4
If you see rotation=-90 (or 90, 180), the player is applying rotation on playback. The pixels themselves are stored in the original orientation. No output means the file has no flag.
To clear the flag without re-encoding (fast, lossless):
ffmpeg -display_rotation 0 -i input.mp4 -c copy output.mp4
-display_rotation is an input option, so it goes before -i. Use this when the pixels are already upright and a stray flag is turning the video in players. Re-encoding a 4K file just to fix a flag wastes minutes of processing time.
Older guides use -metadata:s:v rotate=0 for this. On a current FFmpeg build that command leaves the flag exactly as it was.
To go the other way and bake the flag into the pixels, so every player shows the same picture, re-encode with no rotation filter at all:
ffmpeg -i input.mp4 -c:a copy output.mp4
FFmpeg reads the flag, turns the picture to match, and writes a file with no flag.
Rotate video through an API (no FFmpeg install)
If you're building an app or automation workflow, running FFmpeg locally means managing binaries, dependencies, and server capacity. FFmpeg Micro lets you rotate video with a single HTTP call instead.
90 degrees clockwise via the API:
curl -X POST https://api.ffmpeg-micro.com/v1/transcodes \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"inputs": [{ "url": "https://example.com/input.mp4" }],
"outputFormat": "mp4",
"options": [
{ "option": "-vf", "argument": "transpose=1" },
{ "option": "-c:a", "argument": "copy" }
]
}'
The response includes a job ID. Poll GET /v1/transcodes/{id} until status is completed, then grab the output with GET /v1/transcodes/{id}/download.
For 180-degree rotation, chain the filters in the argument:
{ "option": "-vf", "argument": "transpose=1,transpose=1" }
Same FFmpeg filter syntax, zero local setup. Works from n8n, Make.com, Zapier, or any language that can make HTTP requests.
Common pitfalls when rotating video
1. Forgetting -c:a copy and re-encoding audio. Without it, FFmpeg picks a default audio codec. On some builds that's aac with lower quality settings. Always pass audio through unless you need to change it.
2. Double rotation from a rotation flag. When FFmpeg re-encodes, it applies the flag for you and removes it. If a phone recorded with a flag and you also apply transpose=1, both turns happen and the video ends up a quarter turn past upright. Check for a flag with ffprobe first. If there is one, a plain re-encode already turns the picture, so leave the transpose out. To ignore the flag and rotate only by your filter, put -display_rotation 0 before -i.
3. Aspect ratio breaking in players. Some older players and browsers ignore the display matrix after re-encoding. If the rotated video looks stretched, add explicit dimensions: -vf "transpose=1,setdar=9/16" for portrait output.
4. Container format limitations. WebM (VP9) handles rotation fine. AVI does not support rotation metadata at all. MP4 and MOV are the safest containers for rotated video.
5. Losing quality on repeated rotations. Each re-encode with transpose degrades quality slightly. If you need to rotate and do other transforms (crop, resize, watermark), chain everything into one -vf filter instead of running FFmpeg multiple times.
FAQ
Can I rotate video without re-encoding?
Yes, in MP4 and MOV, by setting the rotation flag. ffmpeg -display_rotation -90 -i input.mp4 -c copy output.mp4 turns the video 90 degrees clockwise in any player that honors the flag. The value is in counter-clockwise degrees, so 90 turns it the other way and 0 clears the flag. No pixel data is touched. Some players and upload pipelines ignore the flag, so if the video has to look the same everywhere, move the pixels with transpose, which needs a re-encode.
What's the difference between transpose and rotate in FFmpeg?
The transpose filter handles 90-degree increments and is the standard approach. The rotate filter supports arbitrary angles (like 45 degrees), but it keeps the original frame size, so the corners of the picture are cut off and the gaps are filled with black. For 90/180/270, always use transpose.
Does rotating video change the file size?
Re-encoding with transpose produces a file roughly the same size, depending on your codec settings (CRF, preset). Metadata-only rotation with -c copy produces an identical file size since no pixels are changed.
How do I rotate video in a Node.js or Python app without installing FFmpeg?
Use a cloud FFmpeg API like FFmpeg Micro. Send an HTTP POST with your video URL and the transpose filter as an option. The API handles processing on cloud infrastructure and returns a download URL. No local FFmpeg binary needed.
Why does my rotated video look correct locally but wrong in the browser?
Players do not all honor the MP4 rotation flag. If the file still carries one, some show the video turned and some do not. Check with the ffprobe command above. A file re-encoded with transpose has no flag left, because FFmpeg applies and removes it during the re-encode. A file made with -c copy keeps its flag: clear it with -display_rotation 0, or re-encode so the rotation is in the pixels.
CLI commands last verified: 2026-10-06 against FFmpeg 8.0.1. API example last verified: 2026-05-24 against FFmpeg Micro API v1.
About Javid Jamae
Founder & CEO at FFmpeg Micro
Javid is a software engineer, author, and entrepreneur with over 25 years of professional software development experience across enterprise, startup, and consulting environments. He founded FFmpeg Micro to make video processing accessible to developers through a simple, automation-first REST API.
You might also like

How to Crop and Resize Video with FFmpeg
Learn how to crop and resize video with FFmpeg using scale, crop, and pad filters. Includes CLI commands, API examples, and TikTok/Reels presets.

How to Convert Video Format with FFmpeg (MP4, WebM, MKV, AVI)
Learn how to convert video between MP4, WebM, MOV, and AVI with FFmpeg CLI commands and the FFmpeg Micro API. Codec table and common pitfalls included.

How to Compress Video with FFmpeg Without Losing Quality
Learn how to compress video with FFmpeg using CRF, two-pass encoding, and preset tuning. Reduce file size by 50-80% without visible quality loss.
Ready to process videos at scale?
Start using FFmpeg Micro's simple API today. No infrastructure required.
Get Started Free