<p>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.</p>

CC BY-SA 3.0
2018-03-28T16:32:40.203Z
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
CC BY-SA 3.0
2018-03-28T16:49:09.673Z
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
CC BY-SA 3.0
2018-03-28T16:55:47.567Z
Hmmm... Would it be feasible to scale both the input video and image to give me a "larger" space for selecting a rectangle?
ilitirit
CC BY-SA 3.0
2018-03-28T17:06:09.213Z
Scaling will introduce artifacts and thus noise.  There's also the [find_rect](https://ffmpeg.org/ffmpeg-filters.html#find_005frect) filter although I haven't used it.
Gyan
CC BY-SA 3.0
2018-03-28T16:25:43.040Z
2018-03-28T16:25:43.040Z
Gyan
<p>I would like to find all frames in a clip that are likely to contain an image at a known position.</p>

<p>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.</p>

<p>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:
<a href="https://i.sstatic.net/n1tqT.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/n1tqT.png" alt="enter image description here"></a></p>

<p>My idea is to create a mask that looks like this:
<a href="https://i.sstatic.net/1wc1s.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1wc1s.png" alt="enter image description here"></a></p>

<p>And apply it to the video such that when the image is not present the resulting frame "looks" like this:
<a href="https://i.sstatic.net/NyfUF.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/NyfUF.png" alt="enter image description here"></a></p>

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

<p>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.  </p>

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

<ffmpeg>
Find frames in video that contain an image
ilitirit
# Find frames in video that contain an image

(Asked by: username_0 on 2018-03-28)

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](https://i.sstatic.net/n1tqT.png)](https://i.sstatic.net/n1tqT.png)

My idea is to create a mask that looks like this:
[![enter image description here](https://i.sstatic.net/1wc1s.png)](https://i.sstatic.net/1wc1s.png)

And apply it to the video such that when the image is not present the resulting frame "looks" like this:
[![enter image description here](https://i.sstatic.net/NyfUF.png)](https://i.sstatic.net/NyfUF.png)

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?

**Tags:** ffmpeg


---

## 1 answers

### Answer by username_1 on 2018-03-28. Score: 1 | Accepted answer

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.

> **Comments:**
> **username_0**: 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.  
> **username_1**: 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.  
> **username_0**: Hmmm... Would it be feasible to scale both the input video and image to give me a "larger" space for selecting a rectangle?  
> **username_1**: Scaling will introduce artifacts and thus noise.  There's also the [find_rect](https://ffmpeg.org/ffmpeg-filters.html#find_005frect) filter although I haven't used it.  

---

