Close modal

Blog Post

Pull out video thumbnails with faces

Development
Mon 14 November 2016
0 Comments


Prerequisite

First off grab this library by Yuri D'Elia here. This is what we'll be using to detect a face present or not in the images.

Some sample data

You'll need video files, these are floating around the internet and I've references them here for this example.

http://www.html5videoplayer.net/videos/toystory.mp4
http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4
The script

The bash script is pretty simple, here it is in full. It requires no arguments - just run it locally.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#!/bin/bash
mkdir frames

while read -r url; do
    echo "${url}"
    wget -qx "${url}"
    local_copy=`find . | grep -e ".mp4$"`
    echo "${local_copy}"
    SKIPTIME="20.00"
    avconv -i "${local_copy}" -r 1/1 -ss $SKIPTIME 'frames/frame%03d.jpg'
    for X in frames/*; do facedetect -q $X && echo "${X}" && mv "${X}" "${local_copy%.*}.jpg" && break; done
    rm "${local_copy}"
    rm frames/*
done < videos2.txt

As you can see SKIPTIME can be overriden to provide the values in seconds to start looking (incase the video has an intro you wish to skip).

Once it is run, the files will be saved in a format matching the directory and site structure they came from (but this can be changed), however if you're creating batch thumbnails from existing content hosted on the web, it'll easy let you save the files.

Results

Here is what came out of it.

Video Thumb
Big Buck Bunny Thumb 1
Toy Story Trailer Thumb 2
Conclusion

It seems to work nicely though I did find sometimes there are some false positives (I processed about 300 image files), overall the approach is solid, if not requiring perhaps a little more finesse in not picking up circles as faces.