FFmpeg Picture in Picture Command on Linux

This article provides a quick overview and a practical guide on how to create a picture-in-picture (PiP) video effect using FFmpeg on Linux. By leveraging the powerful overlay video filter, you can easily overlay a smaller secondary video onto a main background video. Below, we break down the exact command structure, explain what each parameter does, and provide a few advanced tweaks to customize your video layouts.

To create a picture-in-picture effect where a secondary video is placed in the bottom-right corner of the main video, use the following FFmpeg command:

ffmpeg -i main_video.mp4 -i overlay_video.mp4 -filter_complex "[1:v]scale=480:-1[pip]; [0:v][pip]overlay=W-w-10:H-h-10:shortest=1" -c:a aac output.mp4

Understanding how this command works allows you to customize the output to fit your specific needs. The filter_complex flag is the core of this operation, breaking down into two distinct steps:

The positioning variables inside the overlay filter give you precise control over where the smaller video sits:

You can easily change the positioning math to place your video in different corners of the screen depending on your project requirements: