3 # Calin-Andrei Burloiu, 2011, calin.burloiu@gmail.com
5 # This script extracts a thumbnail from a random frame of a video file.
10 echo "Usage: $0 input-video output-image resolution"
17 FFMPEG=/usr/bin/ffmpeg
19 if test ! -f "$in"; then
20 echo "Error: No such file $in"
24 # Choose a random frame
25 str_duration=$(mediainfo --Inform="General;%Duration/String3%" "$in" | cut -d"." -f1)
26 h=$(echo $str_duration | cut -d":" -f1 | sed -r 's/^[0]*//')
27 if [ -z "$h" ]; then h=0; fi
28 m=$(echo $str_duration | cut -d":" -f2 | sed -r 's/^[0]*//')
29 if [ -z "$m" ]; then m=0; fi
30 s=$(echo $str_duration | cut -d":" -f3 | sed -r 's/^[0]*//')
31 if [ -z "$s" ]; then s=0; fi
32 s=$(($h * 3600 + $m * 60 + $s))
34 seek_point=$(echo "$s $RANDOM" | awk '{ print int($1 * $2 / 32767) }')
36 #"$FFMPEG" -i "$in" -ss "$seek_point" -vframes 1 -s "$resolution" -f image2 "$out"
37 "$FFMPEG" -ss "$seek_point" -i "$in" -vcodec mjpeg -vframes 1 -an -s "$resolution" -f rawvideo "$out"