Search code examples
node.jsraspberry-piwebcam

start usb-webcam via Nodejs on Raspberry Pi


I am working on my first raspberry-nodejs project, which I want to use a usb-webcam. I've seen that there are a lot module for interactive with a webcam via node and I have also seen the raspberry 'apt-get motion'... But does anyone know a package where I can turn the the camera on and off via a node-app. and then also define when to take pictures and where to store them?


Solution

  • But does anyone know a package where I can turn the the camera on and off via a node-app?

    node-v4l2camera : https://github.com/bellbind/node-v4l2camera/
    Capturing images from USB(UVC) webcam on Linux machines.

    npm install v4l2camera
    

    Once you got your cam configured, with cam.start() & cam.stop()

    and then also define when to take pictures and where to store them?

    var v4l2camera = require("v4l2camera");
    var cam = new v4l2camera.Camera("/dev/video0");
    if (cam.configGet().formatName !== "MJPG") {
      console.log("NOTICE: MJPG camera required");
      process.exit(1);
    }
    cam.start();
    cam.capture(function (success) {
      var frame = cam.frameRaw();
      require("fs").createWriteStream("result.jpg").end(Buffer(frame));
      cam.stop();
    });