Tobi
Tobi

Reputation: 3

Extract only part of a frame that changed

Is it possible to output only the part of a frame that differs from the last frame as a png image with something like ffmpeg?

Upvotes: 0

Views: 534

Answers (2)

Gyan
Gyan

Reputation: 92998

Since you state, you want to "output only the part of a frame that differs from the last frame", you'll want the tblend filter.

ffmpeg -i in -filter_complex "format=yuva444p,split[diff][out];[diff]tblend=all_expr='if(eq(A,B),0,A)',geq=lum='p(X,Y)':a='if(eq(lum(X,Y)+cb(X,Y)+cr(X,Y),0),0,255)',alphaextract[diff];[out]trim=start_frame=1[out];[out][diff]alphamerge" -vsync vfr out%d.png

The limitation is that if a pixel is originally 0 in both A and B, then that will be a false positive in the output.

Upvotes: 1

VC.One
VC.One

Reputation: 15881

You need to do some pixel differencing. It's easier to do with a For-loop checking the pixels of both bitmaps (frames), Where if same color = make transparent in output bitmap and if not matching values (color) then show as white in output bitmap. This output bitmap could then be encoded as a new/next frame in the output video. But you didn't tell us about your programming language so no further advise on this method...

With just FFmpeg, you could try:

ffmpeg -i test1.mp4 -i test2.mp4 -filter_complex "blend=all_mode=difference" -pix_fmt yuv420p -c:v libx264 out_difference.mp4

For some people it just gives green output (even for me), so if you find a fix for that issue (web research) then this is your solution. Other blend mode's like "blend=all_mode=screen" work fine

Upvotes: 0

Related Questions