How to batch flip videos on Linux using FFmpeg

204

If you have some upside-down or mirror videos you would like to flip to make them look normal and don’t want to do them one by one, you can leverage the job using FFmpeg, a command-line tool for manipulating multimedia files. This tutorial will show you how to batch flip videos horizontally and vertically on Linux using FFmpeg.

Installing FFmpeg

First of all, install FFmpeg on your system using the following command. If you aren’t using a Debian-based distro. Make sure to have it installed from your distro’s repository properly.

sudo apt-get update
sudo apt-get install ffmpeg

Flipping a video horizontally

You can flip a video file horizontally using the following command. Note the -vf hflip option.

ffmpeg -i input.mp4 -vf hflip output.mp4

Flipping a video vertically

You can flip a video file vertically using the following command. Note the -vf vflip option.

ffmpeg -i input.mp4 -vf vflip output.mp4

Batch flipping videos horizontally

Go to the directory where the input videos files you want to flip horizontally are located at. Create an output directory inside it to keep the output video files in a subdirectory to avoid confusion.

mkdir output

Batch flip the input MP4 video files horizontally using the following command. Wait for the process to finish. It will take some time depending on the number of videos and file sizes.

for i in *.mp4; do ffmpeg -i "$i" -vf hflip "output/${i%.*}.mp4"; done

Batch flipping videos vertically

Similar to batch flipping videos horizontally using the command above. Create an output directory, and change the option from -vf hflip to -vf vflip in the command.

for i in *.mp4; do ffmpeg -i "$i" -vf vflip "output/${i%.*}.mp4"; done