How to Mirror Left Side of Video with FFmpeg

This guide provides a straightforward tutorial on how to use FFmpeg to create a mirror effect where the left side of a video is reflected onto the right side. You will learn the exact command-line syntax, understand how the video filters work together to achieve this effect, and see how to apply this to your own video files.

To mirror the left side of a video onto the right side, you need to use FFmpeg’s complex filtergraph (-vf or -filter_complex). The process involves splitting the input video, cropping the left half of both streams, flipping one of the halves horizontally, and then stacking them back together side-by-side.

The FFmpeg Command

Run the following command in your terminal:

ffmpeg -i input.mp4 -vf "split [main][copy]; [main] crop=iw/2:ih:0:0 [left]; [copy] crop=iw/2:ih:0:0, hflip [right]; [left][right] hstack" output.mp4

How the Command Works

The filterchain inside the double quotes (-vf "...") performs the following steps:

  1. split [main][copy]: This duplicates the input video into two identical streams, labeled [main] and [copy].
  2. [main] crop=iw/2:ih:0:0 [left]: This takes the [main] stream and crops it.
    • iw/2 sets the output width to half of the input width.
    • ih keeps the full height.
    • 0:0 starts the crop at the top-left corner (x=0, y=0), effectively capturing only the left half of the video. This stream is labeled [left].
  3. [copy] crop=iw/2:ih:0:0, hflip [right]: This takes the [copy] stream, crops the left half using the same coordinates, and then applies the hflip filter to mirror it horizontally. This stream is labeled [right].
  4. [left][right] hstack: This takes the non-mirrored left half ([left]) and the mirrored left half ([right]) and stacks them horizontally side-by-side to reconstruct a full-width video.