Adding Green Video Overlay with FFmpeg: Define Interval

Abstract: Add a periodic green video overlay to FFmpeg output using the overlay filter with time-based enable expressions.

Created: 2026-10-01 by
To add a green video overlay that appears every minute using FFmpeg, you must use the overlay filter within a filter_complex graph. This approach allows precise control over the timing and positioning of the overlay by calculating the start time for each interval based on the main video's duration.

Understanding the Overlay Filter

The core challenge in periodic overlays is telling FFmpeg exactly when to show and hide the second video stream. Unlike simple concatenation, where you join clips end-to-end, an overlay sits on top of another video layer. The overlay filter takes two inputs: the main background video (input 0) and the overlay video (input 1). To make it appear periodically, you cannot simply loop the overlay indefinitely without masking it out during specific times. Instead, you define the active windows for the overlay using expressions or by splitting the timeline. A common misconception is that setting -stream_loop -1 on the overlay input will automatically handle the repetition correctly within the filter graph. As noted in previous troubleshooting guides, -stream_loop affects the demuxer level, not the filter complex duration handling directly. If you loop the source file externally, you risk memory issues or sync errors if the main video length does not perfectly divide by the loop count. It is safer to generate the overlay pattern dynamically or use a single short clip and reference it with precise timing offsets.

Constructing the Filter Graph

You need to build a filter_complex string that chains your filters. The basic structure involves loading both videos, processing them, and merging them. For a green screen effect, you might also want to apply chroma keying before overlaying, but for a solid green block, the raw overlay is sufficient. The critical part is the x and y coordinates, and more importantly, the enable option. The enable option accepts an expression that evaluates to true or false at each frame. You can use the t variable, which represents the current timestamp in seconds. For example, to show the overlay from second 0 to 60, then hide it from 60 to 120, and repeat this cycle, you can use a modulo operation. The expression mod(t, 60) < 5 would show the overlay for the first 5 seconds of every minute. Adjust the 5 to match the duration of your green overlay clip. Here is the general syntax structure:
ffmpeg -i main.mp4 -i overlay.mp4 -filter_complex "[0:v][1:v]overlay=x=0:y=0:enable='mod(t\,60)<5'[vout]" -map "[vout]" output.mp4
Note the escaping of the comma in mod(t\,60). In many shells, commas inside filter expressions must be escaped to prevent parsing errors. If you are using Windows CMD, you may need different quoting strategies. On Linux/Mac Bash, single quotes around the entire expression and backslash-escaping the comma is standard.

Handling Multiple Intervals

If you need multiple distinct intervals per minute, such as appearing at 0-5s and 30-35s, you combine conditions with logical OR (or) or AND (and).
enable='mod(t,60)<5 or mod(t,60)>=30 and mod(t,60)<35'
This logic ensures the overlay is visible only during those specific windows. The t variable resets its context relative to the filter's start, but since we use mod, it cycles through the minutes seamlessly regardless of the total video length.

Alternative: Using trim and concat

Another robust method avoids complex expressions by physically cutting the main video into segments, inserting the overlay, and then concatenating them. This is useful if you have many different overlay patterns or if the expression engine struggles with performance on very long videos. 1. Use ffmpeg -ss 0 -t 60 -i main.mp4 segment1.mp4 to cut the first minute. 2. Overlay the green clip onto segment1.mp4. 3. Cut the next minute segment2.mp4. 4. Leave segment2.mp4 without the overlay. 5. Repeat for all minutes. 6. Create a list file list.txt with entries like file 'segment1_overlay.mp4' and file 'segment2.mp4'. 7. Run ffmpeg -f concat -i list.txt -c copy final.mp4. This method is less elegant but extremely reliable because it relies on standard muxing rather than real-time filter evaluation. It also helps avoid the excessive memory usage issues sometimes seen with large filter graphs, as discussed in related troubleshooting articles.

Performance Considerations

Real-time filtering with overlay and expressions can be CPU-intensive, especially if you are using high-resolution overlays or additional filters like chromakey. If you encounter dropped frames or slow encoding, consider pre-rendering the filtered segments using the trim and concat method mentioned above. This moves the heavy lifting to disk I/O rather than RAM and CPU during the final muxing phase. Also, ensure your overlay video has the same resolution and frame rate as the main video to prevent rescaling overhead. If they differ, FFmpeg will automatically insert scale and fps filters, which adds latency. Explicitly scaling the overlay to match the main video in the filter_complex gives you more control and often better performance.

Common Pitfalls

One frequent error is forgetting to map the output video stream. When you use filter_complex, FFmpeg does not automatically map the result to the output file. You must explicitly include -map "[vout]" (or whatever label you assigned) in your command line. Without this, the output file will either be empty or contain only audio if you mapped it separately. Another issue is synchronization drift. If your main video has variable frame rates (VFR), the t variable in the expression might not align perfectly with visual frames. Converting the main video to a constant frame rate (CFR) using -r 30 before applying the filter ensures that the timing expressions behave predictably. For more details on handling video streams and avoiding common pitfalls like early audio termination, you might find these resources helpful: Weird FFmpeg Behavior: Shortest Flag Ends Audio Early Troubleshooting Excessive Memory Usage with ffmpeg Overlay Filter

Frequently Asked Questions

Why does my overlay flicker or stutter?

Flickering usually occurs when the overlay's frame rate differs from the main video, causing resampling artifacts. Ensure both videos are converted to the same constant frame rate before filtering, or use the fps filter in your complex graph to normalize the overlay stream.

Can I use this method for non-periodic overlays?

Yes, you can specify exact timestamps instead of using modulo arithmetic. For example, enable='between(t,10,15)' shows the overlay only between 10 and 15 seconds. This provides granular control for one-off events within the video timeline.

What if my green overlay has transparency?

If your overlay is a PNG or WebM with alpha channels, the overlay filter handles transparency automatically. You do not need to use chroma keying unless you are trying to remove a specific color from a video file. The filter blends the alpha channel directly onto the background.

How do I position the overlay in the center?

Use expressions for the x and y coordinates. For center alignment, set x=(main_w-overlay_w)/2 and y=(main_h-overlay_h)/2. These variables refer to the dimensions of the main video input, ensuring the overlay stays centered regardless of resolution changes.

Is there a limit to how many overlays I can stack?

FFmpeg supports multiple layers, but each additional overlay filter increases computational load significantly. Stacking more than three or four overlays may lead to encoding slowdowns or memory exhaustion. For complex compositions, consider rendering intermediate layers to disk files before combining them.

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