From e41b00f86b6618a212009503fb28fe4ba016f83e Mon Sep 17 00:00:00 2001 From: Calin-Andrei Burloiu Date: Thu, 17 Nov 2011 16:49:26 +0200 Subject: [PATCH] extract-thumbnail script improved --- extract-thumbnail | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/extract-thumbnail b/extract-thumbnail index 92e4a1d..c2bcd46 100755 --- a/extract-thumbnail +++ b/extract-thumbnail @@ -1,6 +1,6 @@ #!/bin/bash # -# Calin-Andrei Burloiu, 2010, calin.burloiu@gmail.com +# Calin-Andrei Burloiu, 2011, calin.burloiu@gmail.com # # This script extracts a thumbnail from a random frame of a video file. # @@ -11,18 +11,27 @@ if test $# -ne 3; then exit 1 fi -IN="$1" -OUT="$2" -RESOLUTION="$3" +in="$1" +out="$2" +resolution="$3" FFMPEG=/usr/bin/ffmpeg -if test ! -f "$IN"; then - echo "Error: No such file $IN" +if test ! -f "$in"; then + echo "Error: No such file $in" exit 1 fi # Choose a random frame -DURATION=$(mediainfo --Inform="General;%Duration%" "$IN" | cut -d"." -f1) -SEEK_POINT=$(($DURATION * $RANDOM / 32767 / 1000)) +str_duration=$(mediainfo --Inform="General;%Duration/String3%" "$in" | cut -d"." -f1) +h=$(echo $str_duration | cut -d":" -f1 | sed -r 's/^[0]*//') +if [ -z "$h" ]; then h=0; fi +m=$(echo $str_duration | cut -d":" -f2 | sed -r 's/^[0]*//') +if [ -z "$m" ]; then m=0; fi +s=$(echo $str_duration | cut -d":" -f3 | sed -r 's/^[0]*//') +if [ -z "$s" ]; then s=0; fi +s=$(($h * 3600 + $m * 60 + $s)) -"$FFMPEG" -i "$IN" -ss "$SEEK_POINT" -vframes 1 -s "$RESOLUTION" -f image2 "$OUT" +seek_point=$(echo "$s $RANDOM" | awk '{ print int($1 * $2 / 32767) }') + +#"$FFMPEG" -i "$in" -ss "$seek_point" -vframes 1 -s "$resolution" -f image2 "$out" +"$FFMPEG" -ss "$seek_point" -i "$in" -vcodec mjpeg -vframes 1 -an -s "$resolution" -f rawvideo "$out" -- 2.20.1