Time Lapse Video Using the Dockstar

One of my more interesting presents this Christmas was a crystal growing kit.  I thought it would be cool to take some time lapse video of the crystals growing, but I don’t have a camera/software that’s capable of such things.  Plus I wanted to be able to easily make a video of all the pictures in really any format/framerate/bitrate that I wanted.    This is where the Dockstar (Wifi Webcam) comes in!

The nicest part of the Dockstar is really mjpeg-streamer.  It not only allows you to stream the video from a webcam at whatever framerate (I’m assuming up to 30fps or whatever the camera supports) and whatever resolution you want (that’s supported by the webcam), but it also lets you easily grab single snapshots of the video that is coming out of the webcam.  This is perfect for getting time lapse video!  The only downside is that it’s a webcam, not a really nice camera.

Anyways, I ended up writing a script to download a jpeg image from remote camera’s mjpeg-streamer at the specified interval (in seconds).  The script works well and once CTRL-C is detected, it stops grabbing images and encodes them all into the specified video format.  The script uses ffmpeg to encode the video.  The only real downside to the script at the moment is the filesystem the script saves images to.  Supposedly the ext3 limit for the maximum number of files in any given folder is 32000-ish.  Depending on how many seconds there are between captures, this could limit the length of time that you’re capturing a time lapse video for.  To figure out your maximum capture time depending on the capture interval in seconds: (32000 * interval_seconds)/3600 to get the maximum recording time in hours.  I don’t know if 32000 is the exact number (I’d think 32768 would be more computer-ish), so hopefully that’s a little conservative.  This file limit problem goes away w/ ext4 or reiserfs filesystems (or their limit is much, much higher).

Here’s the script (must be a bash script as I’m using some bash-specific stuff):

trap bashtrap INT
echo "CTRL+C Detected, generating video from files in current directory"


if [ $# -ne 5 ] ; then

echo "Usage: ./time_lapse.sh secs_between_shots path_to_image image_base_filename ffmpeg_options video_filename"
echo "Example: ./time_lapse 10 \"http://user:password@\" testimage \"-r 10 -b 1800\" testvideo.mp4"
echo "The above example will download an image from the specified path to the image every 10 seconds"
echo "and each image will be named testimage0.jpg, testimage1.jpg...etc"
echo "Pressing CTRL-C will terminate the application and use ffmpeg to create a video of the images"

if command -v ffmpeg &>/dev/null ; then
ffmpeg_location=`which ffmpeg` #find out where ffmpeg is on this machine
echo "ffmpeg found in "$ffmpeg_location
echo "ffmpeg not found. Video will not be generated upon exit"

while [ $ctrlc -ne 1 ]                  # Set up a loop control
do                                      # Begin the loop
exec wget $2 -O $3$count.jpg &
count=`expr $count + 1`         # Increment the counter
sleep $1

if [ $ffmpeg_found -eq 1 ] ; then
echo "Executing FFMPEG:    ffmpeg -an -y "$4" -i "$3"%d.jpg" $5
`ffmpeg -an -y $4 -i $3%d.jpg $5`

I’m not the shell-scripting master, so the script probably isn’t the greatest, but hey, it works.  My tabbings didn’t come through so the code looks a bit jumbled.  There’s also stuff that’s supposed to be on a single line, and copying/pasting from here probably will result in newline characters, which the script interpreter won’t like much.  It’ll be easy to fix though.

The script itself is intended to be used w/ a remote mjpeg-streamer source, but it could be adapted for other purposes too.  Also, the options in the usage above for ffmpeg are for setting the framerate (-r) and bitrate (-b) of the encoded video.  -y tells ffmpeg to overwrite an existing video, and -an tells ffmpeg that there’s no audio for the video.  The video encoder type is specified by the filetype extension on the video’s filename (mp4, wmv..etc support adjustable framerates. mpeg does not as far as I know).  WMV also allows you to seek forward and back into the video easily, while mp4 does not (depends on the player).

Here’s a video I made just screwing around with the time lapse capturing: http://www.youtube.com/watch?v=tueA9CUZSQg

This entry was posted in Wifi Webcam. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.