pete_c
Guru
I am looking to do this via Ubuntu.
It would be just an camera FTP to a local NAS.
This is weathercam related.
All my cams firmware now have the option of doing timelapse uploads.
Not looking to go to an external website for this.
I have been able to sort of do this with ZM but would prefer a separate Ubuntu means of doing this.
This post had me searching this morning.
Found a python script that will run on my ZM box here.
First installed python-imaging
sudo apt-get install python-imaging
Teknynja time lapse script
#!/usr/bin/python
# 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):
self.name = name
self.url = url
self.filename = filename
def CaptureImage(self):
camera = urllib.urlopen(self.url)
image_buffer = StringIO.StringIO()
image_buffer.write(camera.read())
image_buffer.seek(0)
image = Image.open(image_buffer)
camera.close()
return image
def TimestampImage(self, image):
draw_buffer = ImageDraw.Draw(image)
font = ImageFont.truetype(FONT_FILENAME, 16)
timestamp = datetime.datetime.now()
stamptext = "{0} - {1}".format(timestamp.strftime(TIMESTAMP_FORMAT), self.name)
draw_buffer.text((5, 5), stamptext, font=font)
def SaveImage(self, image):
with open(self.filename, "a+b") as video_file:
image.save(video_file, "JPEG")
video_file.flush()
def Update(self):
image = self.CaptureImage()
self.TimestampImage(image)
self.SaveImage(image)
print("Captured image from {0} camera to {1}".format(self.name, self.filename))
if __name__ == "__main__":
cameras = []
cameras.append(Camera("porch", "http://username:[email protected]<script data-cfhash='f9e31' type="text/javascript">
/* */</script>/SnapshotJPEG?Resolution=640x480&Quality=Clarity", "cam1.mjpeg"))
cameras.append(Camera("driveway", "http://username:[email protected]
/* *//SnapshotJPEG?Resolution=640x480&Quality=Clarity", "cam2.mjpeg"))
cameras.append(Camera("backyard", "http://username:[email protected]
/* *//SnapshotJPEG?Resolution=640x480&Quality=Clarity", "cam3.mjpeg"))
cameras.append(Camera("sideyard", "http://10.17.42.176/image/jpeg.cgi", "cam4.mjpeg"))
cameras.append(Camera("stairway", "http://10.17.42.175/image/jpeg.cgi", "cam5.mjpeg"))
print("Capturing images from {0} cameras every {1} seconds...".format(len(cameras), LAPSE_TIME))
try:
while (True):
for camera in cameras:
camera.Update()
time.sleep(LAPSE_TIME)
except KeyboardInterrupt:
print("\nExit requested, terminating normally")
sys.exit(0)
Converting to a video script which converts jpgs to mp4 video.
#!/bin/bash
echo "Removing old files..."
rm -fv *.mp4
echo "Converting files to mp4..."
for f in *.mjpeg ; do
t=${f%mjpeg}mp4
echo " Converting $f to $t"
avconv -r 30000/1001 -i "$f" -q 5 "$t" 2>/dev/null
done
echo "Done!"
Uploaded a test file here. Unzip and change the extension to mp4.
Gonna try running this on the RPi2 that is currently running Cumulus weather software and upload the timelapse to the host service.
It would be just an camera FTP to a local NAS.
This is weathercam related.
All my cams firmware now have the option of doing timelapse uploads.
Not looking to go to an external website for this.
I have been able to sort of do this with ZM but would prefer a separate Ubuntu means of doing this.
This post had me searching this morning.
Found a python script that will run on my ZM box here.
First installed python-imaging
sudo apt-get install python-imaging
Teknynja time lapse script
#!/usr/bin/python
# 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):
self.name = name
self.url = url
self.filename = filename
def CaptureImage(self):
camera = urllib.urlopen(self.url)
image_buffer = StringIO.StringIO()
image_buffer.write(camera.read())
image_buffer.seek(0)
image = Image.open(image_buffer)
camera.close()
return image
def TimestampImage(self, image):
draw_buffer = ImageDraw.Draw(image)
font = ImageFont.truetype(FONT_FILENAME, 16)
timestamp = datetime.datetime.now()
stamptext = "{0} - {1}".format(timestamp.strftime(TIMESTAMP_FORMAT), self.name)
draw_buffer.text((5, 5), stamptext, font=font)
def SaveImage(self, image):
with open(self.filename, "a+b") as video_file:
image.save(video_file, "JPEG")
video_file.flush()
def Update(self):
image = self.CaptureImage()
self.TimestampImage(image)
self.SaveImage(image)
print("Captured image from {0} camera to {1}".format(self.name, self.filename))
if __name__ == "__main__":
cameras = []
cameras.append(Camera("porch", "http://username:[email protected]<script data-cfhash='f9e31' type="text/javascript">
/* */</script>/SnapshotJPEG?Resolution=640x480&Quality=Clarity", "cam1.mjpeg"))
cameras.append(Camera("driveway", "http://username:[email protected]
/* *//SnapshotJPEG?Resolution=640x480&Quality=Clarity", "cam2.mjpeg"))
cameras.append(Camera("backyard", "http://username:[email protected]
/* *//SnapshotJPEG?Resolution=640x480&Quality=Clarity", "cam3.mjpeg"))
cameras.append(Camera("sideyard", "http://10.17.42.176/image/jpeg.cgi", "cam4.mjpeg"))
cameras.append(Camera("stairway", "http://10.17.42.175/image/jpeg.cgi", "cam5.mjpeg"))
print("Capturing images from {0} cameras every {1} seconds...".format(len(cameras), LAPSE_TIME))
try:
while (True):
for camera in cameras:
camera.Update()
time.sleep(LAPSE_TIME)
except KeyboardInterrupt:
print("\nExit requested, terminating normally")
sys.exit(0)
Converting to a video script which converts jpgs to mp4 video.
#!/bin/bash
echo "Removing old files..."
rm -fv *.mp4
echo "Converting files to mp4..."
for f in *.mjpeg ; do
t=${f%mjpeg}mp4
echo " Converting $f to $t"
avconv -r 30000/1001 -i "$f" -q 5 "$t" 2>/dev/null
done
echo "Done!"
Uploaded a test file here. Unzip and change the extension to mp4.
Gonna try running this on the RPi2 that is currently running Cumulus weather software and upload the timelapse to the host service.