search
Innovative Web Design and Application Development
PawPrint.net

PawPrint.net News

June 17th, 2011
June 17th, 2011

Automatic Timelapse Video

Building automatic daily time lapse videos

In part to see how it would work, and in part to evaluate the possibilities for some specific applications I have completed a project to create a daily time lapse video that is completely automated using the Axis M1104 web cam, ffmpeg video transcoder, and simple shell scripts.
  • The process, in a nutshell is simple:
  • Take a still image jpeg capture from the cam every minute
  • Stitch these images together into a HD video at the end of the day
  • Pad this combined video with bumpers (intro and exit)
  • Include a soundtrack that changes for ever day of the week
The results have been encouraging so far - Even after leaving the system for 2 days to travel to Victoria.

Completed videos are manually posted to YouTube each day (a process I´m looking to automate as well) To view a sampling of these videos visit the eCoustic Media YouTube Channel. The latest video is included below:



For those with a more technical interest the code to complete this process is included below:

Capture Command (with access credentials removed:

wget --user=xxxx --password=xxxx -O /data/www/images/cam/minute/wc`date +%Y%m%d%H%M%S`.jpg "http://192.168.0.20/axis-cgi/jpg/image.cgi?compression=10&resolution=1280x720"

The above is executed every minute from 0400h until 2300h triggered by a cron job.

Main Process Script
This script runs at 2302h (just after the last capture and creates the actual video. It is split into several scripts so there is the possibility to execute a preview during the day to check on progress (for the impatient coder)

batch.sh

#!/bin/sh
#*********************************
#
# Process daily timelapse
#
#*********************************

count="1"

#*********************************
#* Process Actual Frames
#*********************************
for filename in $(ls -tr /data/www/images/cam/minute/*.*g | sed ´s/ /__/g´)
do
  if [ $count -lt 10 ]; then
    pad="000"
  elif [ $count -lt 100 ]; then
    pad="00"
  elif [ $count -lt 1000 ]; then
    pad="0"
  else
    pad=""
  fi
  
  newname="/data/www/images/cam/minute/frames/$pad$count.jpg"
  filename="$(echo $filename | sed ´s/__/ /g´)"
  echo "copying "$filename" to $newname"
  cp "$filename" "$newname"
  count=$(( $count + 1 ))
done


#*********************************
#* Process Video
#*********************************
/data/www/images/cam/minute/encode.sh

#*********************************
#* Cleanup
#*********************************
rm -Rf /data/www/images/cam/minute/frames/*

#*********************************
#* Rolling Daily Frame Backup
#*********************************
rm -Rf /data/www/images/cam/minute/yesterday/*

mv /data/www/images/cam/minute/*.*g /data/www/images/cam/minute/yesterday/

exit 0


encode.sh

#!/bin/bash
#
# Process Timelapse Video
#

#*********************************
#* Process Frames with no audio
#*********************************
nice -n 19 /usr/local/bin/ffmpeg -r 24 -i /data/www/images/cam/minute/frames/%04d.jpg -b 3700000 -aspect 16:9 -s 1280x720 -f mpeg2video -y /data/www/images/cam/minute/frames/frames.mpg

#*********************************
#* Add Bumpers
#*********************************
cat /data/www/images/cam/minute/leadin/leadin.mpg /data/www/images/cam/minute/frames/frames.mpg /data/www/images/cam/minute/leadin/leadout.mpg > /data/www/images/cam/minute/frames/full.mpg

#*********************************
#* Render final with soundtrack
#*********************************
nice -n 19 /usr/local/bin/ffmpeg -r 24 -i /data/www/images/cam/minute/frames/full.mpg -i /data/www/images/cam/music/0`date +%u`.wav -vcodec libx264 -vpre slow -vpre ipod640 -b 2048000 -bt 921600 -aspect 16:9 -threads 0 -f ipod -y /data/www/images/cam/timelapse`date +%Y%m%d`.mp4


The encoding first renders mpeg2 video to facilitate the concatenation of the bumpers. These were created previously in Adobe Premiere but encoded with the exact same settings using ffmpeg to ensure that the streams were of the exact same format.

Share this:
No Comments
i
You must login or register to post comments Login/Signup
RSS feed Feed Description
Subscribe to the complete PawPrint.net News RSS news feedAll News RSS feed Complete RSS feed
Subscribe to the PawPrint.net News RSS news feed for this category onlyTechnobloggle RSS feed for: Technobloggle
A Rich Site Summary (RSS) feed is an xml data file that provides a summary of the information contained here. It is not designed to be viewed in your browser, but instead by rss reader software. If you do not know what this means - you can safely ignore it, as it is provided for advanced users with rss reader software only.
Copyright © 1992-2024 PawPrint.net
web design and maintenance: PawPrint.net