Skip to content

Instantly share code, notes, and snippets.

@bgerm
Created June 19, 2013 14:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bgerm/5814847 to your computer and use it in GitHub Desktop.
Save bgerm/5814847 to your computer and use it in GitHub Desktop.
Create time-lapse videos with my Foscam FI8910W camera.
#!/bin/sh
# This script will make a timelapse video from a Foscam FI8910W camera by
# downloading the snapshot image every 2 seconds, watermarking it with the
# current time, and then using ffmpeg on those images to make the movie.
#
# Capturing stops on Ctrl-C or 10 hours of elapsed time.
# Note: This was put together hastily and I'm sure the ffmpeg
# options or framerate could be improved.
# Example: ~/timelapse/timelapse.sh ~/timelapse/results/$(date +%m%d%Y)
if [ $# -ne 1 ]
then
echo "Usage: `basename $0` OUTDIR"
exit 65
fi
doexit=0
start=$(date +%s)
end=$(date +%s)
outdir=${1%/}
if [ -d "$outdir" ]; then
echo "Exiting... $outdir already exists."
exit 1;
fi
echo "Capturing images..."
echo "Press Ctrl-C to start stiching the movie."
mkdir -p $outdir
trap ctrl_c INT
function ctrl_c() {
if [ $doexit -eq 1 ]; then
exit 1
fi
doexit=1
filecount=$(ls -1 $outdir/*.jpg 2> /dev/null | wc -l)
echo "\nMaking movie..."
echo "\nfilecount: ${filecount}"
if [ $filecount -gt 0 ]; then
ffmpeg -i $outdir/%05d.jpg -sameq -r 20 $outdir/timelapse.mp4 &&
ffmpeg -i $outdir/%05d.jpg -sameq -r 16 -vf "setpts=0.125*PTS" $outdir/timelapse_fast.mp4 &&
rm -f $outdir/*.jpg
echo "Finished making movie.\n"
else
echo "No images captured to make movie."
fi
exit 1
}
x=1
lastfile=''
while [ $(( $end - $start )) -lt $((10 * 60 * 60)) ]; do
counter=$(printf %05d $x);
file=$outdir/$counter.jpg
response=$(curl --silent --write-out %{http_code} --connect-timeout 5 'http://admin:@192.168.2.118/snapshot.cgi' -o $file)
timestamp=$(date +"%m/%d/%Y %I:%M:%S %p")
if [ "$response" = "200" ]; then
convert $file -pointsize 12 \
-draw "gravity southeast \
fill black text 0,12 '${timestamp}' \
fill white text 1,11 '${timestamp}' " \
$file
lastfile=$file
else
rm -f $file
echo "Could not grab image @ ${timestamp}" >> $outdir/error.log
if [ -n "$lastfile" ]; then
cp $lastfile $file
fi
fi
x=$(($x+1))
end=$(date +%s)
sleep 2
done
@57-Wolve
Copy link

root@ws-alpha:# sh timelapse.sh
Usage: timelapse.sh OUTDIR
root@ws-alpha:
# sh timelapse.sh test
Capturing images...
Press Ctrl-C to start stiching the movie.
timelapse.sh: 38: timelapse.sh: Syntax error: "(" unexpected

How do i fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment