spuder
spuder

Reputation: 18477

How to detect if video file is pure static?

I have a collection of analog video recordings. About 10% of the files are entirely static. How could I programmatically look at all files and delete the files that contain mostly static?

The following utilities have command line options to analyze video, however none have built in functionality to detect the absence of video content.

  1. ffmpeg

  2. ffprobe

  3. HandBrake

I've tried using ffmpeg to export still images and then use image magick to compare the difference between those images. Unfortunately, the difference between an image of static, and actual video content returns nearly the same difference percentage. (9% vs 7%)

ffmpeg -ss 00:30 -i PICT0050.AVI -vframes 1 -q:v 2 output1.jpg

magick compare -metric PSNR output1.jpg output2.jpg diff.jpg
9.2191

magick compare -metric PSNR output1.jpg output3.jpg diff.jpg
7.70127

Comparing sample 1 with sample 2 results in 9% difference
Comparing sample 1 with sample 3 results in 7% difference

Sample 1 enter image description here

Sample 2 enter image description here Sample 3 enter image description here Sample 4 enter image description here Sample 5 enter image description here Sample 6 enter image description here Sample 7 enter image description here

Upvotes: 4

Views: 733

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 207748

It looks like the static images are black and white without any colour - so I would look at the mean saturation and if it is low/zero, I would assume they are static. So, in bash and assuming your images are named sampleXXX.jpg:

for f in sample*jpg; do 
    convert "$f" -colorspace HSL -channel S -separate -format '%M avg sat=%[fx:int(mean*100)]\n' info:
done

Sample Output

sample1.jpg avg sat=0
sample2.jpg avg sat=0
sample3.jpg avg sat=21
sample4.jpg avg sat=0
sample5.jpg avg sat=39
sample6.jpg avg sat=31

which suggests that samples 1,2 and 4 are static.

Upvotes: 4

fmw42
fmw42

Reputation: 53164

Another way is to look at the amount of edges using Imagemagick to rank the amount of noise. The noise images will have more edges.

for img in *; do
edginess=`convert $img -edge 1 -scale 1x1! -format "%[fx:mean]" info:`
echo "$img $edginess"
done

1bidV.jpg 0.0472165
3FJUJ.jpg 0.275502  <---- noise image
QpQvA.jpg 0.332296  <---- noise image
b4Gxy.jpg 0.0428422
gQcXP.jpg 0.0437578
vF1YZ.jpg 0.322911  <---- noise image

Upvotes: 1

Related Questions