FFMPEG: Creating a video, which has the maximum value per pixel of n-input videos

378 views Asked by At

Imagine a collection of short videos, each one showing a shooting star.

I would like to get a composite video of all shooting stars. Not in sequence, at the same time. The (x,y) pixel of the nth frame in the output video should have the maximum value for that (x,y) pixel of the same frame in all the videos.

I know how to do that using images and imagemagick:

magick *.bmp -evaluate-sequence max output.bmp

I need something similar for video. Frame by frame.

Any help would be appreciated. Thanks.

1

There are 1 answers

0
Gyan On

The blend filter in lighten mode does this: it returns the max value of the corresponding inputs pixel-wise.

The blend filter only works with two inputs at a time and both inputs must have the same resolution and pixel aspect ratio. Assuming that's so, template for a 4-input process is

ffmpeg -i 1.mp4 -i 2.mp4 -i 3.mp4 -i 4.mp4
       -filter_complex
       "[0][1]blend=all_mode=lighten[01b];
        [01b][2]blend=all_mode=lighten[012b];
        [012b][3]blend=all_mode=lighten[0123b]"
       -map "[0123b]" output.mp4

Each blend filter terminates with the longer of the inputs, so the end result will be as long as the longest of the inputs.

I've ignored audio handling.