Last active
August 29, 2015 14:15
-
-
Save sdumetz/099a44ff9de8a88fe442 to your computer and use it in GitHub Desktop.
Make a thumbnail of a video using VLC and imagemagick. No real improvement over using ffmpeg except if you have VLC installed and not ffmpeg.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# usage : | |
# @param source video | |
# @param destination | |
set -e | |
### USAGE HELPER ###### | |
usage () { | |
echo "takes a thumbnail from a video" | |
echo "" | |
echo "basic usage : thumbs.sh [OPTIONS] SRC DEST" | |
echo "\t-h --help" | |
echo "\t--size= expected output size" | |
echo "" | |
} | |
### COMMAND LINE ARGS PARSING ######## | |
while [ "$1" != "" ]; do | |
PARAM=`echo $1 | awk -F= '{print $1}'` | |
VALUE=`echo $1 | awk -F= '{print $2}'` | |
case "$PARAM" in | |
-h | --help) | |
usage | |
exit | |
;; | |
--size) | |
SIZE=$VALUE | |
;; | |
*) | |
echo "got param : $PARAM" | |
if [ -z $SOURCE ]; then | |
echo "no source" | |
SOURCE=$PARAM | |
elif [ -z $DEST ]; then | |
DEST=$PARAM | |
else | |
echo "Error : too many arguments" | |
usage | |
exit 1 | |
fi | |
;; | |
esac | |
shift | |
done | |
if [ -z $SOURCE ] || [ -z $DEST ]; then | |
echo "Error : require source and destination filenames" | |
usage | |
exit 1 | |
fi | |
### Varibles Declaration ###### | |
EXTENSION="jpg" | |
FILE=$(mktemp --suffix .$EXTENSION) | |
FILENAME=$(basename $FILE) | |
PREFIX=${FILENAME%.*} | |
DIRNAME=$(dirname $FILE) | |
cvlc $SOURCE \ | |
--rate=1 --video-filter=scene \ | |
--vout=dummy --run-time=0.01 \ | |
--scene-format=$EXTENSION --scene-replace \ | |
--scene-ratio=25 --scene-prefix=$PREFIX \ | |
--scene-path=$DIRNAME vlc://quit | |
WIDTH=$(identify -format "%[fx:w]" $FILE) | |
HEIGHT=$(identify -format "%[fx:h]" $FILE) | |
START_H=$(($HEIGHT/3)) | |
START_W=$(($WIDTH/3)) | |
SIZE_H=$(($HEIGHT-2*$START_H)) | |
SIZE_W=$(($WIDTH-2*$START_W)) | |
#echo "${SIZE_W}x${SIZE_H}+${START_W}+${START_H}" | |
convert -crop "${SIZE_W}x${SIZE_H}+${START_W}+0" -flip $FILE $DEST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment