thumbnail fly generator for 1.0.9

everything about the next not so big update

Moderator: Moderator

User avatar
castorinop
veteran
Posts: 331
Joined: Wed Jun 07, 2006 6:34 pm
Location: Argentina
Contact:

thumbnail fly generator for 1.0.9

Postby castorinop » Mon Dec 10, 2007 1:47 pm

this script generate "on the fly" the thumbnail of videos using inotify-tools

Code: Select all

#!/bin/sh -x

video_mkcovername () {
        var="$1"
        cNAME=${var##*/}
        sNAME=${cNAME%%.*}
        echo "/config/mms/movies/${sNAME}_cover.jpg"
}

thumb-helper () {
filename="$1";
NAME=${filename##*/}
extension="${NAME#*.}"
if [ "$extension" == "avi" -o "$extension" == "mpg" -o "$extension" == "wmv" ]; then
        NEWNAME="${NAME%%.*}"_cover.jpg
        mplayer-thumbnailer "$filename" "~/.mms/movies/$NEWNAME"
fi
}

inotifywait --format "%w|%:e|%f" -q -m -r  \
        -e close_write -e move -e delete \
        "/media" \
  | while read line; do
                fullCMD=`echo $line | cut -d '|' -f 2`
                CMD=`echo $fullCMD | cut -d ':' -f 1`
                subCMD=`echo $fullCMD | cut -d ':' -f 2`
                DIR=`echo $line | cut -d '|' -f 1`
                FILE=`echo $line | cut -d '|' -f 3`
                FILENAME="$DIR$FILE"
                NAME="${FILE%%.*}"
                EXT="${FILE##*.}"

case "$CMD" in
        "DELETE")
                rm `video_mkcovername "$FILENAME"`
                ;;
        "MOVED_FROM")
                old_FILENAME=`video_mkcovername "$FILENAME"`
                if [ -f "$old_FILENAME" ]; then
                        FROM_FILENAME="$old_FILENAME"
                fi
                ;;
        "MOVED_TO")
                if [ -f "$FROM_FILENAME" ]; then
                        mv "$FROM_FILENAME" `video_mkcovername "$FILENAME"`
                        FORM_FILENAME=""
                else
                        thumb-helper "$FILENAME"
                fi
                ;;
        "CLOSE_WRITE:CLOSE")
                thumb-helper "$FILENAME"
                ;;
esac

done


mplayer-thumbnailer

Code: Select all

#!/bin/sh
videofile="$1"
thumbfile="$2"
cmdLENGTH="mplayer -nocache -identify -vo null -ao null -frames 0"
LENGTH=`$cmdLENGTH "$videofile"  | awk -F= '/ID_LENGTH/ {print $2}'| awk -F. '{print $1}'`
RANDOM=0
START=$(((LENGTH / 100) * 15))
END=$(((LENGTH / 100) * 70))
LENGTH=$(($END - $START))
if [ "$LENGTH" -eq 0 ]; then
SHOT=1000
else
SHOT=$((($RANDOM % $LENGTH) + $START))
fi
/usr/bin/mplayer -really-quiet -nojoystick -nolirc -nocache -noautosub -nosound -vf scale -vo jpeg:outdir=/tmp:quality=100 -ao null -ss "$SHOT" -frames 5 -zoom -xy 128 -slave "$videofile"
mv /tmp/00000003.jpg "$thumbfile" || rm -f /tmp/00000003.jpg
rm -f /tmp/00000001.jpg /tmp/00000002.jpg /tmp/00000004.jpg /tmp/00000005.jpg

Return to “1.0.9”

Who is online

Users browsing this forum: No registered users and 1 guest