Reputation: 18477
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.
ffmpeg
ffprobe
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 2
Sample 3
Sample 4
Sample 5
Sample 6
Sample 7
Upvotes: 4
Views: 733
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
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