DEV Community

Javid Jamae
Javid Jamae

Posted on • Originally published at ffmpeg-micro.com

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

Originally published at ffmpeg-micro.com

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
Enter fullscreen mode Exit fullscreen mode

90 degrees counter-clockwise:

ffmpeg -i input.mp4 -vf "transpose=2" -c:a copy output.mp4
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 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
Enter fullscreen mode Exit fullscreen mode

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

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

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.

curl -X POST https://api.ffmpeg-micro.com/v1/transcodes \
  -H "Authorization: Bearer " \
  -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" }
    ]
  }'
Enter fullscreen mode Exit fullscreen mode

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. 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.

3. Aspect ratio breaking in players. Some older players ignore the display matrix after re-encoding. Add explicit dimensions if the rotated video looks stretched.

4. Container format limitations. WebM handles rotation fine. AVI does not support rotation metadata at all. MP4 and MOV are the safest containers.

5. Losing quality on repeated rotations. 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.

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 but pads the output with black bars. For 90/180/270, always use transpose.

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. No local FFmpeg binary needed.

Top comments (0)