Using FFmpeg to Overlay Images on Video Frames

Abstract: Demonstrates how to overlay images on video frames using FFmpeg with precise positioning, timing control, and transparency handling.

Created: 2026-10-08 by
You can overlay images on video frames using FFmpeg’s overlay video filter within the -vf argument. This powerful tool allows you to position a static image or another video stream over your primary footage with precise control over coordinates, timing, and blending modes, enabling everything from simple watermarks to complex visual compositions directly in the command line.

Basic Overlay Syntax

The core of this operation relies on the overlay filter. To use it, you must provide two inputs: the main video stream and the image file to be overlaid. The basic structure involves specifying the input files with -i flags and then chaining the filter into the output command. For example, if you have a video file named input.mp4 and an image file named logo.png, the command structure looks like this:
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=x:y" output.mp4
Here, x and y represent the horizontal and vertical coordinates where the top-left corner of the image will appear. If you omit these values, FFmpeg defaults to placing the image at the top-left corner (0,0). It is crucial to use -filter_complex instead of -vf when dealing with multiple inputs, as standard video filters cannot handle more than one input stream natively without complex graphing.

Positioning the Image

Precise placement is often required for professional-looking results. You can specify exact pixel values for the x and y parameters. For instance, to place a logo 10 pixels from the right edge and 10 pixels from the bottom edge, you would calculate the coordinates based on the video resolution. However, FFmpeg offers dynamic expressions that make this easier. You can use variables such as w (width of the overlay) and W (width of the main video) to create relative positions. To center the image horizontally, you can use the expression (W-w)/2. To keep it at the top vertically, you simply set y=0. A common use case is placing a watermark in the bottom-right corner. The command would look like this:
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=W-w-10:H-h-10" output.mp4
In this example, W-w-10 calculates the distance from the left edge by taking the total width minus the logo width minus 10 pixels of padding. Similarly, H-h-10 handles the vertical positioning. This approach ensures the logo stays correctly positioned regardless of the video's resolution, provided the aspect ratio remains consistent.

Controlling Timing and Duration

By default, the overlay appears throughout the entire duration of the video. If you need the image to appear only during specific timestamps, you can use the enable option within the filter. This allows you to define start and stop times using time expressions. For example, to show the logo only between the 5-second mark and the 10-second mark, you would modify the filter string:
ffmpeg -i input.mp4 -i logo.png -filter_complex "overlay=enable=between(t\,5\,10)" output.mp4
Note that special characters like commas inside the filter string must be escaped with a backslash (\). This feature is particularly useful for adding temporary notifications, subtitles, or animated elements that should not persist for the whole clip.

Handling Transparency and Alpha Channels

Most modern overlays are PNG files with alpha channels, allowing for transparent backgrounds. FFmpeg handles this automatically if the output codec supports transparency, such as WebM or MOV with specific codecs. However, sometimes you may need to explicitly manage the alpha channel or blend mode. If your image has a solid background that you want to remove or blend, you might need additional preprocessing steps. But for standard PNG overlays, ensuring the input image has an alpha channel is sufficient. The overlay filter respects the alpha information, compositing the non-transparent parts of the image onto the underlying video frame. For more advanced blending, such as making the logo semi-transparent, you can adjust the opacity. While the basic overlay filter does not have a direct opacity parameter, you can chain it with other filters or use expressions to modulate the alpha value. Alternatively, pre-processing the image with tools like ImageMagick before feeding it into FFmpeg is a common workflow for complex graphical adjustments.

Common Pitfalls and Troubleshooting

One frequent error occurs when users try to use -vf with multiple inputs. As mentioned earlier, -vf applies to a single input stream. When combining a video and an image, you must use -filter_complex. Another issue arises with incorrect coordinate calculations, leading to the image being cut off or placed outside the visible area. Always verify the resolution of both the source video and the overlay image. Additionally, if the output file is significantly larger than expected, check the encoding settings. Using high bitrates or lossless codecs for the final output can increase file size dramatically. For web distribution, consider using H.264 with a reasonable CRF (Constant Rate Factor) setting to balance quality and file size. For related techniques involving text overlays, you might find our guide on FFmpeg Textbox Padding using boxborderw useful for refining how textual elements interact with video frames. Proper padding and border settings can enhance readability and aesthetic appeal, similar to how image overlays contribute to the overall composition.

Frequently Asked Questions

Why is my overlay appearing in the wrong position?

This usually happens because the default coordinates are set to 0,0 (top-left), or because the resolution of the overlay image differs significantly from the video. Use dynamic expressions like W-w to ensure the position scales correctly with the video dimensions.

Can I overlay a video on top of another video?

Yes, the overlay filter works with two video streams just as well as a video and an image. You simply provide two -i video inputs and apply the filter to combine them into a single output stream.

How do I make the overlay fade in and out?

You can achieve fading effects by animating the opacity using the enable option combined with time-based expressions. For smoother animations, consider using the xfade filter or pre-rendering the transparency changes in external software.

What if my output video has no audio?

When using -filter_complex, FFmpeg does not automatically copy audio streams from the first input. You must explicitly add the -map 0:a flag to include the original audio track in your final output file.

Does the overlay affect the video bitrate?

The overlay itself does not change the target bitrate, but adding complex visual elements can increase the encoding difficulty. This may result in slightly higher bitrate requirements to maintain the same perceived quality, especially if the overlay contains fine details or motion.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More