Timelapse from Meteobridge Camera using Raspberry Pi
Posted: Thu May 06, 2021 5:57 pm
I've recently setup a service using my RaspberryPi to create a daily timelapse movies (.mp4) using the pictures collected and processed by the Meteobridge Weather Cam service. I thought I'd post my code to share with the group.
There's a couple of python scripts. One to capture pictures every 5-minutes (or your choice) and one to process into a timelapse move and upload to your website of choice using FTP.
Collector Python Script
All you need to put in here is the link to your meteobridge camera from the weather services tab.
Timelapse Python Script
Use crontab to run the collector every 5-minutes and the timelapse every hour. I run a final script at the start of a new day to delete all of yesterday's snapshot files.
For those using Brian's Weather34 Aurora template you add a link in the weather34-sidemenu.php file to point to the timelapse.mp4 file using a copy of the code that displays a webcam still image.
Use this line:
repeat it with these changes:
Then copy weather34-large-cam.php to weather34-timelapse.php. Change the following lines:
to
I've additional code to copy the daily one into an archive and a page to display the archive files as well if people are interested.
Enjoy.
There's a couple of python scripts. One to capture pictures every 5-minutes (or your choice) and one to process into a timelapse move and upload to your website of choice using FTP.
Collector Python Script
Code: Select all
import time
from urlgrabber.grabber import urlgrab
snapfile = "/home/pi/cam/snapshot"+time.strftime("%Y%m%d")+time.strftime("%H%M%S")+".jpg"
urlgrab("https://admin.meteobridge.com/cam/<your unique code>/camplus.jpg", snapfile)
Timelapse Python Script
Code: Select all
import datetime
import os
import glob
import ftplib
from os import system
fileList = glob.glob("/home/pi/cam/*.mp4")
# remove old file before re-creating
for filePath in fileList:
try:
os.remove(filePath)
except:
print("Error while deleting file : ". filePath)
# create the .mp4. FPS ultimately determines the length/speed of the movie. 5min = 12 photos/hr = max 144 photos/day. 12 fps = 12 second movie.
fps = 12 # frames per second
dateraw= datetime.datetime.now()
datetimeformat = dateraw.strftime("%Y%m%d_%H:%M:00")
system('ffmpeg -r {} -f image2 -s 1706x960 -nostats -loglevel 0 -pattern_type glob -i "/home/pi/cam/snapshot*.jpg" -vcodec libx264 -crf 25 -pix_fmt yuv420p /home/pi/cam/{}.mp4'.format(fps, datetimeformat))
# ftp the .mp4 to your website
session = ftplib.FTP('ftp.yoursite.com','<userid>','<password>')
file = open('/home/pi/cam/{}.mp4'.format(datetimeformat))
session.storbinary('STOR timelapse.mp4', file)
file.close()
session.quit()
Code: Select all
import os
import glob
fileList = glob.glob("/home/pi/cam/snapshot*.jpg")
for filePath in fileList:
try:
os.remove(filePath)
except:
print("Error while deleting file : ". filePath)
Use this line:
Code: Select all
<?php //webcam option if yes
if ($webcamdevice == "yes") { echo '<a href="weather34-large-cam.php" data-lity data-title="Webcam">';echo $webcamicon2.' Webcam</a><br>';}?>
Code: Select all
<?php //webcam option if yes
if ($webcamdevice == "yes") { echo '<a href="weather34-timelapse.php" data-lity data-title="Timelapse Today">';echo $webcamicon2.' Timelapse</a><br>';}?>
Code: Select all
<?php if (!empty($videoWeatherCamURL) && $videoWeatherCamURL != ' ' && $videoWeatherCamURL != 'Null' && $videoWeatherCamURL != 'null'){?>
<iframe class="videoWeatherCamLarge" allowfullscreen webkitallowfullscreen mozallowfullscreen src="<?php echo $videoWeatherCamURL;?>" frameborder="0"></iframe>
<?php } else {?>
<img src="<?php echo $webcamurl;?>?v=<?php echo date('YmdGis');?>" alt="weathercam" class="webcamlarge">
<?php }?>
Code: Select all
<video controls="controls" class="webcamlarge">
<source src="timelapse.mp4" type="video/mp4">
</video>
Enjoy.