Created
April 21, 2015 13:32
-
-
Save maxpeterson/1b099f3bf99b5bff42b1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
root=$( cd -P "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd) | |
usage=" | |
Usage: `basename $0` [source] [ratio] | |
Generate video poster images. | |
Arguments | |
========= | |
source: Source video folder or file. | |
Defaults to $root/project/media/movies | |
ratio: Scene ratio. | |
Try adjusting ratio (down from 24) if you get black images. | |
" | |
MOVIEDIR=${1:-$root/project/media/movies} | |
RATIO=${2:-500} | |
if [ ! -e $MOVIEDIR ] ; then | |
echo "Folder does not exist: $MOVIEDIR" | |
echo -e "$usage" | |
exit 1 | |
fi | |
if [ -f $MOVIEDIR ] ; then | |
FILES=$MOVIEDIR | |
MOVIEDIR=$(dirname $FILES) | |
fi | |
POSTERDIR=$MOVIEDIR/poster | |
# Find an appropriate VLC command | |
for cmd in 'cvlc' 'vlc -I "dummy"' '/Applications/VLC.app/Contents/MacOS/VLC -I rc'; do | |
type -P $cmd &>/dev/null | |
if [ $? == 0 ]; then | |
CMD="$cmd" | |
break | |
fi | |
done | |
if [ "$CMD" = "" ]; then | |
echo "vlc not found. Not able to generate screenshots" | |
exit 1 | |
fi | |
if [ "$FILES" = "" ]; then | |
FILES=$(shopt -s nullglob; echo $MOVIEDIR/*) | |
fi | |
if test ! -n "$FILES"; then | |
echo "No video files found." | |
exit 1 | |
fi | |
if [ ! -e $POSTERDIR ]; then | |
mkdir $POSTERDIR | |
fi | |
for FILE in $FILES; do | |
if [ -f $FILE ] ; then | |
echo "Generating poster for $FILE" | |
NAME=$(basename $FILE) | |
NAME=${NAME%.*} | |
$CMD $FILE --rate=1 --video-filter=scene --vout=dummy --start-time=1 --stop-time=2 --scene-format=png --scene-ratio=$RATIO --scene-prefix=$NAME --scene-path=$POSTERDIR vlc://quit | |
# Tidy file names | |
#POSTERS=$(shopt -s nullglob; echo $POSTERDIR/${NAME}0*) | |
LASTPOSTER=$(printf '%.5d' $[RATIO + 1]) | |
POSTERS=$(shopt -s nullglob; echo ${POSTERDIR}/${NAME}{$LASTPOSTER,00001}.png) | |
for POSTER in $POSTERS; do | |
if [ -e $POSTER ]; then | |
mv "$POSTER" "${POSTERDIR}/${NAME}.png" | |
rm $POSTERDIR/${NAME}0*.png | |
break | |
fi | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment