Skip to content

Instantly share code, notes, and snippets.

@codebox
Created September 21, 2011 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codebox/1233075 to your computer and use it in GitHub Desktop.
Save codebox/1233075 to your computer and use it in GitHub Desktop.
Shell script to generate tiny still images extracted at 1 second intervals from a video file (requires ffmpeg)
#!/bin/bash
# Set things up...
INFILE=$1
if [[ -z "$INFILE" || ! -f $INFILE ]]; then
echo Please supply the location of a video file
exit 1
fi
OUTDIR=./tiles
STEP=1
CURR=1
if [ ! -d $OUTDIR ]; then
mkdir $OUTDIR
fi
# Find the duration of the video, in seconds
LEN_TXT=`ffmpeg -i $INFILE 2>&1|grep Duration|cut -f4 -d' '|cut -f1 -d'.'| sed 's/:0/:/g' | sed 's/:/ \\* 3600 + /'|sed 's/:/ \\* 60 + /'`
let "LEN=$LEN_TXT"
echo "Duration=$LEN seconds"
FILENAME=`basename $INFILE`
# Make the thumbnail images (32x24 pixels)
while [ $CURR -le $LEN ]
do
PADDED_NUM=`printf "%05d" $CURR`
THUMBFILE=$OUTDIR/$FILENAME.$PADDED_NUM.jpg
echo Processing $CURR of $LEN
ffmpeg -ss $CURR -i $INFILE -vcodec mjpeg -vframes 1 -y -an -f rawvideo -s 32x24 $THUMBFILE >/dev/null 2>&1
let CURR+=STEP
done
echo Finished.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment