惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
U
Unit 42
T
Tailwind CSS Blog
罗磊的独立博客
WordPress大学
WordPress大学
小众软件
小众软件
Recent Announcements
Recent Announcements
博客园 - 聂微东
Jina AI
Jina AI
云风的 BLOG
云风的 BLOG
博客园 - 【当耐特】
爱范儿
爱范儿
Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
V
V2EX
博客园 - 三生石上(FineUI控件)
I
InfoQ
雷峰网
雷峰网
G
Google Developers Blog
阮一峰的网络日志
阮一峰的网络日志
B
Blog
腾讯CDC
A
About on SuperTechFans
博客园 - 叶小钗

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
FFmpeg Overlay Filter: Picture-in-Picture and Compositing
Javid Jamae · 2026-06-26 · via DEV Community

Javid Jamae

Originally published at ffmpeg-micro.com

You need to put one video on top of another, and FFmpeg's documentation reads like a math textbook. The overlay filter is one of the most used filters in FFmpeg, but getting the positioning, scaling, and timing right takes more trial and error than it should.

This guide covers the overlay filter from basic image-on-video compositing to timed picture-in-picture with multiple streams.

How the FFmpeg Overlay Filter Works

The overlay filter takes two video inputs and stacks one on top of the other. The first input is the background (main video), and the second is the foreground (the overlay). You control placement with x and y coordinates.

The basic syntax inside filter_complex:

ffmpeg -i main.mp4 -i logo.png -filter_complex "[0:v][1:v]overlay=10:10" output.mp4

This places logo.png at 10 pixels from the left and 10 pixels from the top of main.mp4. Two inputs, one filter, x and y coordinates.

You need -filter_complex instead of -vf whenever you're working with multiple inputs.

Position Variables for Dynamic Placement

Hardcoding pixel values breaks the moment your input resolution changes. FFmpeg gives you position variables that reference the dimensions of each stream at runtime:

  • W and H refer to the main video's width and height
  • w and h refer to the overlay's width and height

Bottom-right corner with 10px padding:

ffmpeg -i main.mp4 -i watermark.png -filter_complex "[0:v][1:v]overlay=W-w-10:H-h-10" output.mp4

Center the overlay:

ffmpeg -i main.mp4 -i overlay.png -filter_complex "[0:v][1:v]overlay=(W-w)/2:(H-h)/2" output.mp4

FFmpeg Picture-in-Picture with Scaling

Chain a scale filter before the overlay:

ffmpeg -i main.mp4 -i pip.mp4 -filter_complex \
  "[1:v]scale=320:180[pip];[0:v][pip]overlay=W-w-20:20" \
  output.mp4

Video-on-Video vs. Image-on-Video

When overlaying video on video, set eof_action to handle duration mismatches:

ffmpeg -i main.mp4 -i overlay.mp4 -filter_complex \
  "[0:v][1:v]overlay=10:10:eof_action=pass" output.mp4

Timed Overlays

Show overlays only during specific time windows:

ffmpeg -i main.mp4 -i lower_third.png -filter_complex \
  "[0:v][1:v]overlay=0:H-h:enable='between(t,5,15)'" output.mp4

Running Overlays via API

FFmpeg Micro runs your overlay commands as API calls. Same filter syntax, no infrastructure:

curl -X POST https://api.ffmpeg-micro.com/v1/transcodes \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "inputs": [
      {"url": "https://storage.example.com/main.mp4"},
      {"url": "https://storage.example.com/overlay.png"}
    ],
    "outputFormat": "mp4",
    "options": [
      {"option": "-filter_complex", "argument": "[0:v][1:v]overlay=W-w-10:H-h-10"}
    ]
  }'

Common Pitfalls

  • Pixel format mismatches: Use format=auto on the overlay filter for PNG transparency
  • Missing audio: Add -map 0:a -c:a copy to carry audio through
  • Using -vf instead of -filter_complex: -vf only works with a single input

FAQ

How do I put a logo in the corner of a video? Use overlay=W-w-10:H-h-10 for bottom-right placement.

Can I overlay video on video? Yes, same syntax. Use eof_action=pass if the overlay is shorter.

How do I make picture-in-picture? Scale first, then overlay: [1:v]scale=320:180[pip];[0:v][pip]overlay=W-w-20:20