ffmpegvideo-processingtransposevideo-rotationapi

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

·Javid Jamae·5 min read
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:

ValueDirectionOutput dimensions
090° counter-clockwise + vertical flipSwapped
190° clockwiseSwapped
290° counter-clockwiseSwapped
390° clockwise + vertical flipSwapped

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 in the container metadata (the rotate tag in MP4/MOV files). iPhones do this constantly.

Check for metadata rotation with ffprobe:

ffprobe -v quiet -show_entries stream_tags=rotate -of default=nw=1 input.mp4

If you see TAG:rotate=90 (or 180, 270), the player is applying rotation on playback. The pixels themselves are stored in the original orientation.

To fix metadata-only rotation without re-encoding (fast, lossless):

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

This strips the rotation tag. Use this when the video already looks correct in ffprobe output but players rotate it. Re-encoding a 4K file just to fix a metadata tag wastes minutes of processing time.

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 metadata. If a phone recorded with a rotate=90 metadata tag and you apply transpose=1, the video ends up rotated 180 degrees. Check metadata with ffprobe first. Strip the tag with -metadata:s:v rotate=0 if it exists.

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?

Only if the rotation is metadata-based. Use ffmpeg -i input.mp4 -c copy -metadata:s:v rotate=0 output.mp4 to strip the rotation tag without touching pixel data. If you need to actually move pixels (transpose), re-encoding is required.

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 pads the output with black bars to fit the rotated frame. 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?

Browsers interpret the MP4 display matrix differently than desktop players. After rotating with transpose, add -metadata:s:v:0 rotate=0 to clear any leftover rotation metadata. This forces all players to show the video the same way.

*Last verified: 2026-05-24 against FFmpeg 3.3.3 and 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.

Software EngineeringVideo ProcessingFFmpegCloud ArchitectureAPI DesignAutomation

Ready to process videos at scale?

Start using FFmpeg Micro's simple API today. No infrastructure required.

Get Started Free