Timelapse from Meteobridge Camera using Raspberry Pi

All about the standard Meteobridge devices based on mobile routers from TP-Link, D-Link, ASUS

Moderator: Mattk

Post Reply
User avatar
jasonmfarrow
Gold Boarder
Gold Boarder
Posts: 249
Joined: Mon May 25, 2020 4:21 pm
Contact:

Timelapse from Meteobridge Camera using Raspberry Pi

Post by jasonmfarrow »

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

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)
All you need to put in here is the link to your meteobridge camera from the weather services tab.

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()
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.

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)
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:

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.'&nbsp;Webcam</a><br>';}?>
repeat it with these changes:

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.'&nbsp;Timelapse</a><br>';}?>
Then copy weather34-large-cam.php to weather34-timelapse.php. Change the following lines:

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 }?>
to

Code: Select all

<video controls="controls" class="webcamlarge">
<source src="timelapse.mp4" type="video/mp4">
</video>
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.
Regards
Jason
https://jmfweather.uk | @jasonmfarrow
Post Reply