How to Flip Video Vertically with FFmpeg
This article explains how to use the FFmpeg vflip video
filter to flip videos vertically (upside down). You will learn the basic
command syntax for vertical flipping, how to combine it with other
filters like horizontal flipping, and how to apply these changes while
maintaining optimal video and audio quality.
Basic Vertical Flip Command
To flip a video vertically, use the -vf (video filter)
flag followed by the vflip filter. The basic command
structure is as follows:
ffmpeg -i input.mp4 -vf "vflip" output.mp4Here is what each part of the command does: *
-i input.mp4: Specifies the path to your input video file.
* -vf "vflip": Applies the video filter named
vflip to flip the image upside down. *
output.mp4: Specifies the name and format of the resulting
output file.
Flipping Vertically and Horizontally
If you need to flip your video both vertically and horizontally
(which is equivalent to a 180-degree rotation), you can chain the
vflip and hflip filters together by separating
them with a comma:
ffmpeg -i input.mp4 -vf "vflip,hflip" output.mp4Preserving Video and Audio Quality
By default, FFmpeg will re-encode the video stream when applying filters. To ensure the output maintains high video quality and to avoid unnecessary re-encoding of the audio track, you can specify the audio codec to be copied directly and set a constant rate factor (CRF) for the video:
ffmpeg -i input.mp4 -vf "vflip" -c:a copy -crf 20 output.mp4-c:a copy: Stream copies the audio directly from the source without re-encoding, saving time and preserving original audio quality.-crf 20: Sets the video quality. Lower values produce higher quality files (the sane range is typically between 18 and 28, where 18 is visually lossless).