π· π¨ an easy-to-use API for downloading and streaming from public Michigan Tech webcams
npm i mtu-webcams
The below example assumes you have FFMPEG installed and it is in your $PATH
.
If you don't have FFMPEG installed or don't want to install it, check out ffmpeg-static.
const fs = require('fs');
const Webcams = require('mtu-webcams');
const cams = new Webcams();
(async () => {
// Get all webcams and save in instance
await cams.init();
// Log discovered webcams
console.log(cams.getAll()); // => [ ... ]
// Download yesterday's timelapse to 'recording.mp4'
const yesterday = new Date(new Date().getTime() - (86400 * 1000));
cams.byName('Campus Aerial').streamRecording(yesterday).pipe(fs.createWriteStream('recording.mp4'));
// Get a current snapshot and save to 'snapshot.jpg'
cams.byName('Campus Aerial').streamImage().pipe(fs.createWriteStream('snapshot.jpg'));
// Stream ~5 seconds of video and save to 'stream.flv'
const stream = cams.byName('Campus Aerial').streamVideo();
stream.pipe(fs.createWriteStream('stream.mp4'));
setTimeout(() => {
stream.destroy();
}, 5000);
})();
Main cameras class.
Scrape Michigan Tech's website to retrieve all published webcams.
Returns Array<Camera> discovered cameras
Get all cameras saved in instance.
Gets camera by ID.
id
Number of camera
Returns Camera
Gets camera by name.
name
String of camera
Returns Camera
Main camera class.
$0
Object (optional, default{}
)$0.imageURL
$0.name
$0.description
$0.ffmpegPath
Returns the URL to a static snapshot.
Returns String
Returns a stream of the latest static snapshot.
Returns stream.Readable
Returns the URL to a live m3u8
playlist.
Returns String
Returns a live video stream from the webcam.
options
Object (optional, default{}
)options.format
String format specifier passed to FFMPEG (optional, default'flv'
)
Returns stream.Readable
Returns the URL for a MP4 recording.
date
Date of recording
Returns String
Returns a recording as a stream.
date
Date of recording to retrieve
Returns stream.Readable