FFmpeg - How to replace the image of a video with a png without modifying the audio?

Abstract: Replace video frames with a static PNG while preserving the original audio stream without re-encoding.

Created: 2026-08-20 by
Use the FFmpeg command line to replace video frames with a static PNG while preserving the original audio stream. By mapping the input video and audio separately, you can force the encoder to reuse the existing audio codec without re-encoding, ensuring perfect quality and speed. This approach is ideal for creating thumbnails, watermarks, or static overlays where only the visual component needs updating.

Understanding the Stream Mapping Strategy

The core challenge in replacing video content without touching audio lies in how FFmpeg handles stream selection by default. When you provide multiple inputs, FFmpeg often tries to encode all streams that have a corresponding output. To prevent this, you must explicitly control which streams are copied and which are processed. The key is to use the -c:a copy flag, which tells FFmpeg to simply copy the audio data from the source file to the destination file without any decoding or encoding overhead. This ensures zero loss in audio quality and drastically reduces processing time. You also need to handle the video stream carefully. Since you are introducing a new visual element (the PNG), the video stream cannot be copied; it must be generated from scratch using the nullsrc or color video source combined with the overlay filter, or more commonly, by looping the single PNG image to match the duration of the audio. However, the most robust method for a complete replacement involves generating a new video stream that lasts as long as the audio track.

Preparing Your Inputs

Before running the command, ensure your PNG file is high-quality and has the desired resolution. If the PNG dimensions do not match the target video resolution, FFmpeg will automatically scale it, but this might introduce slight blurring or pixelation depending on the scaling algorithm used. It is best practice to resize the PNG to match the original video resolution beforehand using an image editor or a quick FFmpeg conversion step. Additionally, check the duration of your original video's audio track. You can determine this by running ffprobe -i input.mp4 and looking at the Duration field for the audio stream. This information helps you decide if you need to trim the output or loop the image. For most cases, you want the final video to last exactly as long as the audio file, regardless of the original video's frame count. If you are dealing with complex audio setups, such as multiple language tracks, you may need to map specific audio streams. Refer to our guide on How to Add Random Music (Defined Folder) for Multiple Video with FFMPEG for insights into managing multiple audio streams effectively. Understanding stream mapping is crucial when you want to keep certain audio channels while discarding others during the muxing process.

Executing the Command

The standard command structure involves three main parts: input specification, filter graph definition, and output configuration. Here is the breakdown of the essential flags:
  • -i input_video.mp4: Specifies the source video containing the audio.
  • -loop 1 -i image.png: Loops the PNG image indefinitely so it can cover the entire audio duration.
  • -t duration: Limits the output length to match the audio. You can get the duration dynamically or specify it manually.
  • -c:v libx264: Encodes the new video stream using the H.264 codec.
  • -c:a copy: Copies the audio stream directly without re-encoding.
  • -shortest: Stops encoding when the shortest input stream ends, which is usually the audio.
A practical command looks like this:
ffmpeg -i input.mp4 -loop 1 -i image.png -t $(ffprobe -v error -show_entries format=duration -of csv=p=0 input.mp4) -filter_complex "overlay=0:0" -c:v libx264 -crf 23 -preset fast -c:a copy output.mp4
In this example, -filter_complex "overlay=0:0" places the PNG image at the top-left corner of the video frame. If you want to center it, you would use overlay=(W-w)/2:(H-h)/2. The -crf 23 setting provides a good balance between file size and quality, while -preset fast speeds up the encoding process. It is important to note that if your audio has gaps or silence at the end, the video will extend to fill that time. If you encounter issues with audio sync or missing sound, check the encoding logs. Sometimes, incorrect stream mapping leads to silent outputs. For troubleshooting audio-related warnings, see FFmpeg Warning and No Sound on the Encoding Video to understand common pitfalls in audio handling.

Handling Variable Frame Rates

When replacing video images, the output video will have a constant frame rate determined by the encoder settings. If the original video had a variable frame rate (VFR), the new video will be CFR (Constant Frame Rate). This is generally acceptable for most playback scenarios, including web streaming and local media players. However, if you need to preserve the exact timing of events relative to the audio, ensure that the frame rate chosen matches the original video's average frame rate to avoid drift over long durations. You can specify the frame rate explicitly using -r fps. For example, adding -r 30 forces the output to 30 frames per second. This is useful if you want to reduce the file size further or standardize the output across different videos. Remember that lowering the frame rate too much can make the video appear choppy, even though the image is static. A frame rate of 1-5 FPS is often sufficient for static image replacements if smooth motion is not required.

Finalizing and Verification

After the command completes, verify the output file by playing it in a media player. Check that the audio plays correctly and synchronizes with the start of the video. Inspect the video frames to ensure the PNG is displayed correctly and covers the entire duration. If the audio is out of sync, review the -t parameter and the duration extraction method. For more advanced techniques involving text overlays or animations, consider exploring Combine Images and Draw Text on Each Image with Animation Xfade. These methods build upon the same principles of stream mapping and filtering but add dynamic elements to your static base.

Frequently Asked Questions

Why is my output video black?

This usually happens if the overlay filter parameters are incorrect or if the image path is invalid. Ensure that the overlay=0:0 coordinates are within the bounds of the video frame. Also, verify that the PNG file is readable and not corrupted.

Can I keep the original video's resolution?

Yes, FFmpeg automatically inherits the resolution from the first input video unless you specify a different scale filter. The PNG image will be scaled to fit this resolution during the overlay process. If you want to change the resolution, add a scale filter before the overlay.

How do I remove the audio entirely?

To remove audio, simply omit the -c:a copy flag and do not map the audio stream. You can explicitly discard audio by using -an in the command line, which disables audio recording entirely.

What if the audio is longer than the video?

The -shortest flag ensures the output stops when the shortest stream ends. If you want the video to continue for the full audio duration, use -t with the audio duration value. If the audio is shorter, the video will stop early unless you extend the image loop duration.

Is it possible to add a fade effect to the PNG?

Yes, you can use the fade filter in the filter complex. For example, overlay=0:0,fade=in:0:30 would fade in the image over the first 30 frames. You can adjust the start time and duration of the fade to suit your needs.

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