How to Flip a Video with FFmpeg (hflip and vflip Filters)

작성자

카테고리:

← 피드로
DEV Community · Javid Jamae · 2026-07-20 개발(SW)

Javid Jamae

Originally published at ffmpeg-micro.com

Front-facing camera footage is mirrored. Text reads backwards, logos are reversed, and the left-right orientation is wrong. If you’re processing selfie video, screen recordings from mobile devices, or any source that captured a mirror image, you need to flip it before the output goes anywhere useful.

To flip a video horizontally with FFmpeg, use the hflip video filter: ffmpeg -i input.mp4 -vf hflip -c:a copy output.mp4. For a vertical flip, replace hflip with vflip.

Flip vs. Rotate

This trips people up constantly. A flip mirrors the frame along an axis. A rotation spins it. Horizontal flip (hflip) mirrors left to right, like looking in a mirror. A 90-degree rotation turns the entire frame sideways, changing the orientation and usually the resolution dimensions too.

If someone tells you their video is “upside down,” they probably want vflip or a 180-degree rotation. A 180-degree rotation is actually identical to combining hflip and vflip together, which we’ll cover below.

Horizontal Flip with hflip

The hflip filter mirrors the video along the vertical axis. Every frame gets its pixels reversed left-to-right. This is the filter you want for selfie correction, fixing mirrored webcam footage, or creating a mirror effect for social media content.

ffmpeg -i input.mp4 -vf hflip -c:a copy output.mp4

Enter fullscreen mode Exit fullscreen mode

The -vf hflip flag applies the horizontal flip filter. The -c:a copy flag passes the audio stream through without re-encoding, which saves time and avoids any quality loss on the audio side.

The video stream does get re-encoded. FFmpeg has to decode each frame, flip the pixel data, and encode it again. You can’t flip a video with stream copy on the video track because the actual pixel data needs to change.

Vertical Flip with vflip

The vflip filter mirrors the video along the horizontal axis, flipping it upside down. Every frame gets its rows of pixels reversed top-to-bottom.

ffmpeg -i input.mp4 -vf vflip -c:a copy output.mp4

Enter fullscreen mode Exit fullscreen mode

You’ll run into vertical flip less often than horizontal. The most common use case is correcting footage from cameras mounted upside down, like security cameras or action cameras with inverted mounts.

Combining hflip and vflip for 180-Degree Rotation

Chaining both filters together gives you the equivalent of a 180-degree rotation. The frame gets mirrored horizontally and vertically, which produces the same result as spinning it halfway around.

ffmpeg -i input.mp4 -vf "hflip,vflip" -c:a copy output.mp4

Enter fullscreen mode Exit fullscreen mode

The filter chain runs left to right. FFmpeg applies hflip first, then vflip to the already-flipped output. The order doesn’t matter for this specific combination since the end result is the same either way. It does matter when you start mixing flips with other filters like scaling or cropping.

Preserving Audio

Both examples above use -c:a copy to pass the audio through untouched. This is almost always what you want. Flipping video has nothing to do with the audio stream, so re-encoding it just wastes time and adds a generation of lossy compression for no reason.

If you leave out -c:a copy, FFmpeg will re-encode the audio using its default codec for the output container. For MP4, that’s usually AAC. The quality difference on a single re-encode is minimal, but there’s no upside when stream copy is available.

Common Pitfalls

Forgetting that video gets re-encoded

You can’t use -c:v copy with flip filters. The pixel data is changing, so FFmpeg needs to decode and re-encode the video stream. If you try -c:v copy -vf hflip, FFmpeg will throw an error. This means your output file size and quality depend on your encoder settings. If you need to match the original quality closely, set your bitrate or CRF value explicitly:

ffmpeg -i input.mp4 -vf hflip -c:v libx264 -crf 18 -c:a copy output.mp4

Enter fullscreen mode Exit fullscreen mode

Confusing flip with transpose

FFmpeg also has a transpose filter that combines rotation with an optional flip. If you use transpose=1 expecting a simple mirror, you’ll get a 90-degree clockwise rotation instead. Stick with hflip and vflip when you just need mirroring. Use transpose only when you actually need to rotate by 90 or 270 degrees.

Not accounting for metadata rotation

Some mobile video files store rotation in metadata rather than in the actual pixel data. FFmpeg auto-rotates based on metadata by default. If your input has a rotation flag in its metadata and you apply hflip, you get unexpected results because FFmpeg applies the auto-rotation before your filter. To disable auto-rotation and work with the raw pixel data, add -noautorotate:

ffmpeg -noautorotate -i input.mp4 -vf hflip -c:a copy output.mp4

Enter fullscreen mode Exit fullscreen mode

Flipping Video at Scale with the FFmpeg Micro API

Running these commands locally works fine for one-off jobs. When you need to flip hundreds or thousands of videos programmatically, shelling out to FFmpeg from your application code gets messy fast. You’re managing processes, handling failures, provisioning compute, and babysitting encoding queues.

FFmpeg Micro gives you a REST API that runs FFmpeg filters in the cloud, including hflip and vflip. Send a POST request with your filter chain and get back the processed video:

curl -X POST https://api.ffmpeg-micro.com/v1/transcodes \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": [{"url": "https://example.com/input.mp4"}],
    "outputFormat": "mp4",
    "options": [
      {"option": "-vf", "argument": "hflip"},
      {"option": "-c:a", "argument": "copy"}
    ]
  }'

Enter fullscreen mode Exit fullscreen mode

No infrastructure to manage. No FFmpeg installation to maintain. Just an API call with the same filter syntax you already know.

FAQ

How do I mirror a video in FFmpeg?

Use the hflip video filter to mirror a video horizontally in FFmpeg: ffmpeg -i input.mp4 -vf hflip -c:a copy output.mp4. This reverses the frame left-to-right, producing a mirror image of the original footage.

What is the difference between hflip and vflip in FFmpeg?

The hflip filter mirrors the video along the vertical axis, flipping it left-to-right like a mirror reflection. The vflip filter mirrors the video along the horizontal axis, flipping it upside down. You can combine both with -vf "hflip,vflip" to get a 180-degree rotation.

Can I flip a video without re-encoding the audio?

Yes. Add -c:a copy to your FFmpeg command to pass the audio stream through without re-encoding. The video stream will still be re-encoded because the pixel data changes during a flip, but the audio stays untouched.

How do I rotate a video 180 degrees with FFmpeg?

Combine hflip and vflip filters: ffmpeg -i input.mp4 -vf "hflip,vflip" -c:a copy output.mp4. This mirrors the frame both horizontally and vertically, which produces the same result as a 180-degree rotation.

Does flipping a video affect quality?

Flipping requires FFmpeg to re-encode the video stream, which can reduce quality depending on your encoder settings. To minimize quality loss, use a low CRF value (like 18) with libx264. The audio stream isn’t affected if you use -c:a copy.

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다