How to add a PNG overlay on a video using FFmpeg

FFmpeg is an incredibly powerful tool you can use for manipulating video
by Jon Yongfook ·

Contents

    FFmpeg is an incredibly powerful tool you can use for manipulating video. Here's how to add PNG overlays onto a video using FFmpeg.

    Examples

    A video with a static PNG overlay:

    A video with a sequenece of PNG overlays:

    Disclaimer: in the following examples I will not be setting any video / audio codec flags since you will likely want to choose your own. The following examples all use FFmpeg defaults for codecs and framerates.

    Overlay a static PNG

    You may want to overlay a static PNG to add a watermark or some kind of frame around a video.

    Assuming that you have a video named video.mp4 and an overlay named overlay.png - and that the video and overlays are of the same dimensions, the FFmpeg command to overlay the PNG on the video is as follows:

    ffmpeg -y -i video.mp4 -i overlay.png -filter_complex [0]overlay=x=0:y=0[out] -map [out] -map 0:a? test.mp4
    

    If your video is of a different size to the overlay, or you need to standardize the size of the video before applying the overlay, you will need to use the scale and crop commands that FFmpeg offers.

    Overlay a sequence of PNGs

    Overlaying a sequence of multiple PNGs onto a video is also possible. A common use case for this would be to add hard-coded subtitles onto a video, that need to display at specific points in the video.

    This is more challenging as it requires knowing the times in the video where you want the overlay to be visible.

    Assuming that you have a video named video.mp4 and 3 overlays named 1.png 2.png 3.png - and that they video and overlays are of the same dimensions, the FFmpeg command to overlay the PNGs on the video is as follows:

    ffmpeg -y -i video.mp4 -i 1.png -i 2.png -i 3.png -filter_complex [0][1]overlay=enable='between(t,0,3)':x=0:y=0[out];[out][2]overlay=enable='between(t,3,6)':x=0:y=0[out];[out][3]overlay=enable='between(t,6,9)':x=0:y=0[out] -map [out] -map 0:a? new.mp4
    

    This would spread the overlays evenly out across a 9 second video. As you can see, the key to this is using the enable between feature of FFmpeg, and understanding the timestamps of when in your video you want to hide and show the different PNG overlays.

    Again, if you need to scale / crop the video to fit a certain size, you can do this all in one command using the scale and crop commands that FFmpeg offers.

    Use the Bannerbear API

    If you need an easy way to apply PNG overlays whether single or multiple - especially if you want a way to make changes on the fly to an overlay (e.g. apply a static watermark with today's date, or a title) then you can try using the Bannerbear API.

    It's a REST API that makes some of these types of common FFmpeg operations much more simple, so that you don't have to worry about cropping / scaling / timestamping. It's also highly scalable so you don't have to worry about managing cloud FFmpeg instances - it's all done for you :)

    Here are some quick API examples:

    Applying a static overlay on a video via API

    Applying multiple overlays on a video via API

    About the authorJon Yongfook@yongfook
    Jon is the founder of Bannerbear. He has worked as a designer and programmer for 20 years and is fascinated by the role of technology in design automation.

    How AI Is Changing Content Creation and Why You Should Care as A Developer

    AI is changing content creation. Combining AI and media APIs like Bannerbear, you can build automated pipelines for OG images, quote graphics, carousel posts, and more!

    How to Build a Telegram Chatbot to Create Custom Images on Demand with Bannerbear (Node.js)

    If you’re looking to build a Telegram chatbot that can automatically generate images for social media, blogs, marketing, and more based on user’s input text and image, this step-by-step Node.js guide will show you exactly how to do it.

    From CSV to Branded PDF: Complete Automation Tutorial for Certificates, Invoices, Invitations, and More with Bannerbear

    Whether you’re a developer or a non-coder, you’ll learn how to automate the batch creation of PDFs for certificates, invoices, invitations, and more from data stored in CSV or Airtable in this article.

    Automate & Scale
    Your Marketing

    Bannerbear helps you auto-generate social media visuals, banners and more with our API and nocode integrations

    How to add a PNG overlay on a video using FFmpeg
    How to add a PNG overlay on a video using FFmpeg