I was wondering if it's possible to get the percentage of difference between a video and an static image using avconv (from libav)

I have a surveillance camera constantly providing an RTSP video feed. The camera is statically pointing to the floor. I know how the picture looks like when everything is ok (I have an screenshot of it). Is there a way, using avconv and its magicall filters to get a percentage of variation between the the screenshot and the video coming from the camera? It would be something like the blackframe filter, but instead of having the percentage of "black" in the image, I would like to get the percentage of difference between the screenshot and the video coming from the camera.

I know that there's a lot of possible caveats, such as changes in illumination, tiny movements from the camera, but... I'm kind of curious.

I am running Ubuntu 64 bits (kernel 3.8.0-29) 12.04 with avconv version 0.8.9



You don't say what application you're attempting to do with this information but given you're dealing with a security camera I'd suggest taking a look at the motion package.

You can do something along the lines that you're asking, where motion will show the delta between a reference image and a video feed.


ss #1   ss #2


I also found this blog post that discusses a feature that might prove useful in solving your problem. The article's titled: Scene change detection with ffmpeg (avconv) to extract meaningful thumbnails.


The good news now are that we can employ automated tools to do just that. Ffmpeg (avconv) has all the stuff we need in its libavfilter library to extract still images from a video not every x seconds but every time the video image significantly changes (what more or less equals a scene change). This magic is commonly known as scene change detection.

One approach is to let the video codec do the hard work. Most codecs employ a “key frame” identification technique, that means “this frame is a new scene” (I-frame) and subsequent images change only slightly from that “master frame” and so the codec can store the difference only (B-Frames) instead of full frames. Now, in ffmpeg Stefano Sabatini’s select filter goes through the video and triggers a save of the respective frame only when it encounters an I-Frame / key-frame (probably the beginning of a new scene)

    $ ffmpeg -vf “select=’eq(pict_type,I)’” -i somevideo.mp4 \
            -vsync 0 -f image2 /tmp/thumbnails-%02d.jpg

This approach works, but isn’t perfect. That why Clément Boesch added scene, a scene detection subfilter for select. If your build of ffmpeg has this code, you can call it like this:

    $ ffmpeg -vf “-vf select=’gt(scene\,0.9)’” -i somevideo.mp4 \
            -vsync 0 -f image2 /tmp/thumbnails-%02d.jpg

In case your ffmpeg/avconv complains about “Undefined constant or missing ‘(‘ in ‘scene’” you probably don’t have the scene detection code in your compile of libavfilter/vf_select.c.


If ffmpeg/avconv complains about “”Missing ‘)’ or too many args in …” you probably used the examples from the docs, with an escaped comma, no surrounding quotes etc. Make sure that you include the whole “filtergraph” in quotes, like -vf “” where has our “select=…” stuff, including single quotes.

  • Thank you for your answer, sim. I had seen that article :-) I didn't use it because I understood that it uses key-frames as a marker of a scene change, and I thought that it wouldn't work, but maybe is worth to keep an investigation... Thank you. I'll try your suggestions and I'll let you know – BorrajaX Nov 18 '13 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.