🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

linuxcam

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linuxcam

Capturing images from webcam and converting to rgb24. Linux only (v4l2)

1.0.6
latest
Source
npm
Version published
Weekly downloads
4
-55.56%
Maintainers
1
Weekly downloads
 
Created
Source

node-linuxcam

Capturing images from webcam and converting to rgb24. Linux only (v4l2)

Installation

npm install linuxcam

Usage

var cam = require('linuxcam');
cam.start("/dev/video0", 320, 240);
var frame = cam.frame(); // Buffer

The buffer contains rgb24 data and you can convert it using jpeg-fresh module.

var Jpeg = require('jpeg-fresh').Jpeg;
var jpeg = new Jpeg(frame.data, frame.width, frame.height, 'rgb');
var jpeg_image = jpeg.encodeSync(); // Buffer

Simple live streaming example with SocketIO

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var cam = require('linuxcam');
var Jpeg = require('jpeg-fresh').Jpeg;

cam.start("/dev/video0", 320, 240);

function update(socket) {
  var frame = cam.frame();
  var jpeg = new Jpeg(frame.data, frame.width, frame.height, 'rgb');
  var jpeg_frame = jpeg.encodeSync();
  socket.emit("frame", jpeg_frame.toString('base64'));
  setTimeout(function() {
    update(socket);
  }, 40);
}

io.on('connection', function(socket){
  socket.on('error', function(err){
    console.log("ERROR: "+err);
  });
  update(socket);
});

http.listen(9639, function(){
  console.log('listening on *:9639');
});

Client

<!DOCTYPE html>
<html>
  <head>
    <script src="https://cdn.socket.io/socket.io-1.3.5.js"></script>
  <head>
  <body>
    <canvas id="canvas" width="320" height="240"></canvas>
    <script>
      socket = io("http://localhost:9639");
      var canvas = document.getElementById("canvas");
      var ctx = canvas.getContext("2d");

      var image = new Image();
      image.onload = function() {
        ctx.drawImage(image, 0, 0, 320, 240);
      };

      socket.on('frame', function (frame) {
        image.src = "data:image/jpeg;base64," + frame;
      });
    </script>
  </body>
</html>

MIT license

Keywords

cam

FAQs

Package last updated on 03 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts