Search code examples
videoffmpegvideo-processing

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?


Solution

  • 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.