0

I would like to find all frames in a clip that are likely to contain an image at a known position.

My idea is to grab a still from the video, cut the image and create a mask, feed the video and mask into ffmpeg, use a filter to apply the mask over the video, calculate the difference between the current frame and mask and try to detect if the entire image is black which would indicate that the image is present in the frame.

For example, suppose I have a video where the logo on the right appears at exactly the same spot with the same dimensions several times throughout the video: enter image description here

My idea is to create a mask that looks like this: enter image description here

And apply it to the video such that when the image is not present the resulting frame "looks" like this: enter image description here

But when it does match the blended difference should result in a black screen which I can detect using blackframe.

I've gotten as far as blacking out the actual image, but I'm not sure how to black out the surrounding part of the frame.

Is this possible using ffmpeg, or is there perhaps a different way of doing the same thing?

1 Answer 1

1

You don't need to black out the entire frame. Once you've blacked out the logo portion, apply crop filter to select a rectangular portion entirely within the logo area. Then run blackframe/blackdetect on that canvas. The cropped result will srill retain the original timestamps.

4
  • The problem is the example I gave is not 100% representative of my use case. The image I'm looking for is complex and has transparency within (imagine a logo made up of thin strands or tubes), so It's hard to specify a rectangular region "within" the logo.
    – ilitirit
    Commented Mar 28, 2018 at 16:32
  • That's not insurmountable. Let's say 45% of the image is fully opaque. Select a rect region within and set blackframe to flag frames with black area equal or greater than 45%. Actual figure will depend on fully opaque area within the rect, of course.
    – Gyan
    Commented Mar 28, 2018 at 16:49
  • Hmmm... Would it be feasible to scale both the input video and image to give me a "larger" space for selecting a rectangle?
    – ilitirit
    Commented Mar 28, 2018 at 16:55
  • Scaling will introduce artifacts and thus noise. There's also the find_rect filter although I haven't used it.
    – Gyan
    Commented Mar 28, 2018 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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