Contacting HomeSeer This Week

HomeSeer is open and operational this week. All orders are being processed and shipped as usual. However, some staff are working from home. If you need to contact HomeSeer for support or customer service, please use our Email or Chat options.
See more
See less

Adding time lapse / video creating to Rasberry Pi2

  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding time lapse / video creating to Rasberry Pi2

    16th of October, 2015

    Adding time lapse / videos using one Python script and one bash script.

    1 - Install Python on your RPI2 if it is not already installed
    2 - sudo apt-get install python-imaging
    3 - Python script

    # Number of seconds between frames:
    LAPSE_TIME = 30
    # Name of truetype font file to use for timestamps (should be a monospace font!)
    FONT_FILENAME = "UbuntuMono-B.ttf"
    # Format of timestamp on each frame
    TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S"
    # Command to batch convert mjpeg to mp4 files:
    #  for f in *.mjpeg; do echo $f ; avconv -r 30000/1001 -i "$f" "${f%mjpeg}mp4" 2>/dev/null ; done
    import urllib
    import sys, time, datetime
    import StringIO
    import Image, ImageDraw, ImageFont
    class Camera:
        def __init__(self, name, url, filename):
   = name
            self.url = url
            self.filename = filename
        def CaptureImage(self):
            camera = urllib.urlopen(self.url)
            image_buffer = StringIO.StringIO()
            image =
            return image
        def TimestampImage(self, image):
            draw_buffer = ImageDraw.Draw(image)
            font = ImageFont.truetype(FONT_FILENAME, 16)
            timestamp =
            stamptext = "{0} - {1}".format(timestamp.strftime(TIMESTAMP_FORMAT),
            draw_buffer.text((5, 5), stamptext, font=font)
        def SaveImage(self, image):
            with open(self.filename, "a+b") as video_file:
      , "JPEG")
        def Update(self):
            image = self.CaptureImage()
            print("Captured image from {0} camera to {1}".format(, self.filename))
    if __name__ == "__main__":
        cameras = []
        cameras.append(Camera("porch", "http://username:password@", "cam1.mjpeg"))
        cameras.append(Camera("driveway", "http://username:password@", "cam2.mjpeg"))
        cameras.append(Camera("backyard", "http://username:password@", "cam3.mjpeg"))
        cameras.append(Camera("sideyard", "", "cam4.mjpeg"))
        cameras.append(Camera("stairway", "", "cam5.mjpeg"))
        print("Capturing images from {0} cameras every {1} seconds...".format(len(cameras), LAPSE_TIME))
            while (True):
                for camera in cameras:
        except KeyboardInterrupt:
            print("\nExit requested, terminating normally")
    4 - Bash script to convert / compress video files.


    echo "Removing old files..."
    rm -fv *.mp4
    echo "Converting files to mp4..."
    for f in *.mjpeg ; do
        echo "  Converting $f to $t"
        avconv -r 30000/1001 -i "$f" -q 5 "$t" 2>/dev/null
    echo "Done!"
    5 - copy a font of choice to same said directory.

    18th of October, 2015

    Moved the script over to the RPi2 running CumulusMX and autostarting it via a Cron job. Works well.

    19th of October, 2015

    Testing the script on the Homeseer 3 Zee-2 device. You can just link to the time lapse video in Homeseer 3 and create an event for conversion.

    The conversion program hits the RPi2 CPU stuff:

    Command python /video/
    CPU 0.4 %

    Manual running of bash script:
    Command avconv -r 30000/1001 -i cam1.mjpeg -q 5 cam1.mp4
    CPU 356 %

    Might move it to the HS3 Pro big box.
    Attached Files
    Last edited by Pete; February 15th, 2016, 09:06 PM.
    - Pete

    Auto mator
    Homeseer 3 Pro - (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU 16Gb- Mono 6.8X
    Homeseer Zee2 (Lite) - (Linux) - Ubuntu 18.04/W7e - CherryTrail x5-Z8350 BeeLink 4Gb BT3 Pro - Mono 6.8X
    HS4 pro - - Ubuntu 18.04/W7e 64 bit Intel Kaby Lake CPU - 32Gb - Mono 6.8X

    X10, UPB, Zigbee, ZWave and Wifi MQTT automation. OmniPro 2, Russound zoned audio, Smartthings hub, Hubitat Hub, and Home Assistant