Use your Raspberry Pi Camera Module with Node.js
NOTE: Currently only supports still image capture.
-
Hardware
- Raspberry Pi
- Raspberry Pi Camera module
-
Software
- Raspberry Pi camera enabled
- Node.js 8 or later installed
npm install raspberry-pi-camera-native
// require module
const raspberryPiCamera = require('raspberry-pi-camera-native');
// add frame data event listener
raspberryPiCamera.on('frame', (frameData) => {
// frameData is a Node.js Buffer
// ...
});
// start capture
raspberryPiCamera.start();
Listen for raw data events (partial frame data), data
is a Node.js Buffer
raspberryPiCamera.on('data', callback(data));
Listen for frame events (full frame data), frameData
is a Node.js Buffer
raspberryPiCamera.on('frame', callback(frameData));
raspberryPiCamera.start(options, callback);
Options is a object, with the following defaults:
{
width: 1280,
height: 720,
fps: 30,
encoding: 'JPEG',
quality: 75
}
Supported values:
width
:32
to2592
(v1 camera) or3280
(v2 camera)height
:16
to1944
(v1 camera) or2464
(v2 camera)fps
:1
to90
encoding
:'JPEG'
(hardware accelerated),'GIF'
,'PNG'
,'PPM'
,'TGA'
,'BMP'
(see mmal_encodings.h for others)quality
: 1 - 100 (JPEG encoding quality)
raspberryPiCamera.pause(callback);
raspberryPiCamera.resume(callback);
raspberryPiCamera.stop(callback);