Created
August 9, 2010 23:04
-
-
Save vain/516292 to your computer and use it in GitHub Desktop.
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/bash | |
# Capture a series of images to be used in a time-lapse movie. | |
# Based on http://demaya.de/wp/2010/08/mit-ffmpeg-zeitraffervideos-erstellen/ | |
# Default settings, parse command line arguments. | |
sleeptime='1' | |
defaultduration='30' | |
stopdate=$(( $(date +%s) + defaultduration )) | |
capsdir='/tmp/caps' | |
while (( $# > 0 )) | |
do | |
case $1 in | |
-s) sleeptime="$2"; shift ;; | |
-u) stopdate=$(date -d "$2" +%s); shift ;; | |
-d) stopdate=$(( $(date +%s) + $2 )); shift ;; | |
-t) capsdir="$2"; shift ;; | |
*) | |
cat <<EOF | |
Capture a series of images to be used in a time-lapse movie. | |
$0 [-s <n>] [-u <date> | -d <n>] [-t <dir>] | |
-s <n> | |
Sleep <n> seconds after each captured frame. Default is | |
$sleeptime second(s). | |
-u <date> | |
Stop capturing at <date>. | |
or | |
-d <n> | |
Stop capturing after <n> seconds. Default duration is | |
$defaultduration second(s). | |
-t <dir> | |
Save captured images in <dir>. Default is \`$capsdir'. | |
Examples of usage: | |
$0 -s 2 -u '2010-08-10 10:30' -t ~/mycaps | |
$0 -s 2 -d 15 -t ~/mycaps | |
EOF | |
exit 1 | |
;; | |
esac | |
shift | |
done | |
# Prepare and cleanup on exit. | |
tmpfile="$(mktemp)" | |
trap 'rm -v "$tmpfile"' 0 | |
mkdir -p "$capsdir" || exit 1 | |
# Capture until we've reached the given time. | |
while (( $(date +%s) < stopdate )) | |
do | |
filename="$capsdir/pic$(printf %08d $i).jpg" | |
ffmpeg -f video4linux2 -s 640x480 -r 1 -i /dev/video0 -vframes 1 \ | |
-f image2 "$tmpfile" | |
convert "$tmpfile" \ | |
-gravity SouthWest \ | |
-box white -draw "text 0,0 '$(date)'" \ | |
"$filename" || exit 1 | |
sleep $sleeptime | |
(( i++ )) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment