Search code examples
videoffmpegvideo-processingvideo-editing

can ffmpeg perform frame wise image calculations?


I would like to divide each frame of a video by an image that I would like to provide as an additional input. Can ffmpeg perform such image calculations? I could not find any examples.

This would be a kind of background correction. The input image is the background, for example the median of a large number of frames. (often people use a backgroundSUBTRACTION, but I want to use division)

currently I am doing this in openCV and python. I process each frame like this:

(vidMed is the background image)

import cv2
vidIn=cv2.VideoCapture(input.avi)
vidOut=cv2.VideoVriter(output.avi)

while true
    ret, frame = vidIn.read()
    bgDiv=frame/vidMed
    vidOut.write(bgDiv)

I was hoping this may run faster using ffmpeg


Solution

  • yes, blend works!

    ffmpeg.exe 
    -i videoIn.avi 
    -i imageIn.avi 
    -filter_complex "[1:0] setsar=sar=1 [1sared];[0:0][1sared]blend=all_mode='divide':repeatlast=1[int];
    -out.avi
    

    (imageIn.avi is just one frame)