How to Overlay Video in Video Using FFmpeg

This article explains how to use the FFmpeg overlay video filter to create a picture-in-picture (PiP) effect. You will learn the exact command-line syntax required to scale a secondary video and position it over a main background video at specific coordinates.

To overlay a second video inside a main video, you must use FFmpeg’s filter_complex flag. This allows you to scale the secondary video (so it does not block the entire background) and then position it using coordinates.

Here is the standard command to scale a picture-in-picture video and position it in the bottom-right corner:

ffmpeg -i main_video.mp4 -i pip_video.mp4 -filter_complex "[1:v]scale=400:-1[pip];[0:v][pip]overlay=main_w-overlay_w-20:main_h-overlay_h-20:shortest=1" -c:a aac output.mp4

How the Command Works

Alternative Positioning Coordinates

You can change the positioning of the picture-in-picture video by adjusting the x and y mathematical expressions inside the overlay filter: