Flip Videos with FFmpeg: hflip vs. vflip

Summary

Pixel shares a practical guide to flipping videos with FFmpeg using hflip for left-right mirroring and vflip for top-bottom mirroring. It explains why flips require video re-encoding, how they differ from rotation, and how to copy audio; the example uses a 720×1280 clip with pixel-exact checks.

DEV Community

How to Flip a Video With FFmpeg (hflip and vflip Are Mirrors, Not Rotates, and -c copy Cannot Do Them)

Short answer: to flip a video with FFmpeg, re-encode through hflip or vflip: ffmpeg -i input.mp4 -vf hflip -c:v libx264 -pix_fmt yuv420p -c:a copy flipped.mp4
hflip is a left–right mirror. vflip is a top–bottom mirror. The frame size stays the same (here, 720×1280). That is not a rotate: transpose=1 would turn this clip into 1280×720. And despite what autocomplete offers for "ffmpeg flip video without re encoding", a flip is a video filter, so -c:v copy is rejected: Filtering and streamcopy cannot be used together. Audio can still be stream-copied. Below are pixel-exact measurements on a real 8-second clip, a small Python module, and five pytest checks. The test clip The fixture is a real generated example from Voor's Enzo Fernandez Celebration page: a vertical 720×1280 H.264 + AAC clip, 24 fps, 193 frames, 8.041667 s, with stadium crowd sound. MD5 of the file is 3f8a3a6abc3da386c4d6628e6ff56ff9. curl -O https://cdn.voor.ai/voor/keyword-landing/enzo-fernandez-celebration/v20261019/touchline-blue-v2.mp4
ffprobe -v error -show_entries stream=codec_name,width,height,nb_frames,sample_rate -count_frames \
- of default=nw=1 touchline-blue-v2.mp4

width=720

height=1280

nb_frames=193

codec_name=h264

codec_name=aac

sample_rate=44100

(Tested with FFmpeg 9.0.1, Python 3.13, pytest 9.2.0.) Mistake 1: treating a flip as a rotate ffmpeg flip video 90 degrees shows up in US-English autocomplete next to the horizontal/vertical queries. A 90° rotate changes the axes. A flip does not. ffmpeg -i touchline-blue-v2.mp4 -vf hflip -frames:v 1 -f rawvideo -pix_fmt rgb24 hflip.rgb
ffmpeg -i touchline-blue-v2.mp4 -vf transpose=1 -frames:v 1 -f null -
The first command still writes a 720×1280 frame. transpose=1 would write 1280×720. On the raw RGB24 first frame, hflip is exactly the Python left–right mirror of the source — every row reversed, zero differing bytes. vflip is exactly the top–bottom mirror. If you wanted the clip upside down and backwards left-to-right, that is hflip,vflip, and it is byte-identical to rotate=PI (a 180° rotate). It is not a 90° rotate. Mistake 2: expecting a flip without re-encoding "ffmpeg flip video without re encoding" is a real autocomplete suggestion. This is what FFmpeg 9.0.1 does with it: ffmpeg -i touchline-blue-v2.mp4 -vf hflip -c:v copy -c:a copy copy.mp4

Filtergraph 'hflip' was specified, but codec copy was selected.

Filtering and streamcopy cannot be used together.

Error opening output files: Invalid argument

The process exits non-zero (234 here) and writes no file. A horizontal flip has to rewrite every macroblock; the original bitstream cannot be copied. There is no lossless -c:v copy path for hflip or vflip. If you only needed to tag a player to mirror at display time, that would be a different (and poorly supported) metadata trick — and it would not change the pixels, which is what a flip is supposed to do. Mistake 3: re-encoding the audio when you only flipped the picture The video has to be re-encoded. The audio does not. With -c:a copy the AAC bitstream is identical to the source: MD5 5843435af71daac1e832f8b54fe25bdf on both the original and the flipped file, 131354 bytes. You keep the stadium crowd exactly as it was, and you do not pay a second AAC encode. Flipping twice is also exact on the raw frame: hflip,hflip returns the original 720×1280 RGB24 first frame with zero differing bytes. That is a useful sanity check before you trust a longer filter chain. A small module that flips and checks the pixels flip.py wraps the operations the tests actually use: decode the first frame to raw RGB24 (optionally through a filter), build a Python mirror to compare against, attempt a stream-copy flip (which must fail), and re-encode a flipped file while copying the audio. """Flip a video with FFmpeg (hflip/vflip) and prove the pixels actually moved."""
from future import annotations

import json
import subprocess
from pathlib import Path

WIDTH = 720
HEIGHT = 1280

def _run(cmd: list[st...
Flip Videos with FFmpeg: hflip vs. vflip
Powered by Readybot.io

The latest from Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …