Search code examples
androidffmpegvideo-processingvideo-encoding

Overlay frame PNG animation over video with FFmpeg


Previously, I had no experience with FFmpeg and I really need help. And this is my first question on Stack Overflow. There is a task described below, I use ffmpeg-for-android.

We have an input (20 seconds long, 30 fps) mp4 video and for example 30 PNG images of the same resolution as video. We need to create a transparent looped 30 fps animation from the sequence of images. And after that, overlay the input mp4 video with the layer of the animation created in the first step. In this way if we have a 20 sec / 30 fps video and 30 images (1 second of animation), animation should be repeated 20 times during the video. Perhaps this problem can be solved more easily with the help of FFmpeg?

Can anyone help me in this matter?


Solution

  • Use

    ffmpeg -i video.mp4 -framerate 30 -loop 1 -i img%d.png
           -filter_complex overlay=shortest=1 out.mp4
    

    Use img%d.png for files named img1.png, img2.png, img3.png..

    Use img%04d.pngfor files named img0001.png, img0002.png, img0003.png..