One overlay puts a second video in the corner of the first: scale=-2:480 and pad give it a 6 px white border over 1920x1080. ReelSDK renders the 10-second result for under three quarters of a cent, at $0.02 per compute minute.
Picture-in-picture video with ffmpeg
Picture-in-picture is two videos and one overlay, and ReelSDK's API rendered ours in about 19 seconds. Scale the inset to 480 px tall, pad it for a border since overlay has none, and set shortest=1 so a longer inset can't freeze the main picture at the end.
GuidesUpdated
ffmpeg -i main.mp4 -i inset.mp4 -filter_complex \
"[1:v]scale=-2:480,pad=iw+12:ih+12:6:6:white[pip];\
[0:v][pip]overlay=W-w-40:H-h-40:shortest=1[v]" \
-map "[v]" -map 0:a -c:v libx264 -crf 20 -c:a copy pip.mp4The inset is scaled to 480 px tall, padded 6 px for a white border and placed 40 px from the corner. The main video's audio is kept.
Variations
The other commands you will need
Bring the inset in at 2 s
setptsdelays the inset's frames by 2 s andenablekeeps the overlay off until then.late start ffmpeg -i main.mp4 -i inset.mp4 -filter_complex \ "[1:v]scale=-2:480,pad=iw+12:ih+12:6:6:white,setpts=PTS-STARTPTS+2/TB[pip];\ [0:v][pip]overlay=W-w-40:H-h-40:enable='gte(t,2)':shortest=1[v]" \ -map "[v]" -map 0:a -c:v libx264 -crf 20 -c:a copy pip-late.mp4
The flags
The options in these commands
| Flag | What it does | Used here |
|---|---|---|
scale=-2:480 | 480 px tall, width from the aspect ratio rounded to an even number | Both |
pad=iw+12:ih+12:6:6:white | Adds 6 px of white on every side: the border | Both |
overlay=W-w-40:H-h-40 | Bottom-right corner, 40 px in | Both |
shortest=1 | Ends the output when the shorter input ends; the default is 0 | Both |
setpts=PTS-STARTPTS+2/TB | Shifts the inset's timestamps 2 s later | Late start |
enable='gte(t,2)' | Turns the overlay on from 2 s | Late start |
-map 0:a | Keeps the main video's audio; the inset's is dropped | Both |
Sources: ffmpeg filters: overlay, ffmpeg filters: pad, checked November 2026.
Why shortest=1
Our inset runs almost a second longer than the main video. Without shortest=1 the output video ran to the end of the inset, while the audio, copied from the main clip, stopped earlier. For that last stretch the main picture froze and only the inset moved, because overlay repeats the last frame of an input that has ended.
With shortest=1 the output stops with the main video, right where the audio ends. If the inset should play to its end instead, trim it or pad the main clip, and decide which audio to keep.
The border is just padding
There is no border option in overlay. pad=iw+12:ih+12:6:6:white grows the inset by 12 px in each direction and centers it, which leaves 6 px of white on every side: 270x480 became 282x492. Any color name or hex value works.
scale=-2:480 keeps the width even, which libx264 needs for the usual yuv420p video. -1 would have kept the exact ratio and could give an odd width.
Starting the inset later
enable='gte(t,2)' alone hides the inset for 2 s, but the inset keeps playing underneath, so it appears 2 s into its own clip. Adding setpts=PTS-STARTPTS+2/TB moves its frames 2 s later, so it starts from its first frame. We checked a frame on each side: no border pixels at 1.5 s, the whole border at 2.5 s.
Without installing ffmpeg
The same command as one API call
Send the same args to POST /v1/ffmpeg with both video URLs in inputs. Each job runs ffmpeg 8.1 on a fresh machine at $0.02 per compute minute, billed per second; this one finished in about 19 seconds and cost under three quarters of a cent.
curl "https://api.reelsdk.com/v1/ffmpeg?wait=60" \
-H "Authorization: Bearer $REELSDK_KEY" \
--json '{
"inputs": {
"main.mp4": "https://api.reelsdk.com/f/lib/demo/landscape.mp4",
"inset.mp4": "https://api.reelsdk.com/f/lib/demo/clip.mp4"
},
"args": [
"-i", "main.mp4", "-i", "inset.mp4", "-filter_complex",
"[1:v]scale=-2:480,pad=iw+12:ih+12:6:6:white[pip];[0:v][pip]overlay=W-w-40:H-h-40:shortest=1[v]",
"-map", "[v]", "-map", "0:a", "-c:v", "libx264", "-crf", "20", "-c:a",
"copy", "pip.mp4"
],
"outputs": ["pip.mp4"]
}'FAQ
Questions, answered
How do I put one video in the corner of another with ffmpeg?
Scale the second input and overlay it: ffmpeg -i main.mp4 -i inset.mp4 -filter_complex "[1:v]scale=-2:480[p];[0:v][p]overlay=W-w-40:H-h-40:shortest=1" -c:a copy out.mp4.
Why does my picture-in-picture video freeze at the end?
One input ended and overlay repeats its last frame. Add shortest=1 to stop with the shorter input.
How do I add a border around the inset?
Pad it before the overlay: pad=iw+12:ih+12:6:6:white adds a 6 px white border.
Can I make picture-in-picture videos with an API?
Yes. POST the same args to https://api.reelsdk.com/v1/ffmpeg with both video URLs in inputs. It runs ffmpeg 8.1 for $0.02 per compute minute, billed per second.
- Put two videos side by side with ffmpegPlace videos next to each other with hstack, on top of each other with vstack, or in a 2x2 grid with xstack, after scaling them to match.
- Add a watermark or logo to a video with ffmpegPut a PNG logo in a corner with overlay: scale it, make it semi-transparent, keep it off the edge, or show it only for the first seconds.
- Remove a green screen with ffmpeg chromakeyKey out a green backdrop with chromakey, clean the green edges with despill, put a new background behind it or export a transparent WebM.
- Resize a video with ffmpegScale a video with scale=w:h: keep the aspect ratio with -2, fit a 1080x1920 frame with pad, and fix the odd-size error.
- ffmpeg -filter_complex explainedLabels, commas and semicolons: how a filtergraph wires inputs to outputs, with four working graphs and the errors they fix.
- Watermark videoStamp a PNG logo on every frame at any position and opacity with one ffmpeg call, about two thirds of a cent per 30 s clip.
- FFmpeg onlineRun your own ffmpeg command on your files in the browser, free and without installing or uploading anything.
- height not divisible by 2libx264 refuses a 4:2:0 frame with an odd width or height. Scale with -2, round odd sources to even, or send the args to an API.
Sources, checked November 2026
Ready to build?
Ship video from your app today
Your first $0.50 is free, and one key covers every endpoint.
