npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

webcam-http-streaming

v1.1.2

Published

Simple wrapper around ffmpeg for http webcam streaming

Readme

webcam-http-streaming

Stream a webcam over http with node.js

API

  • createHTTPStreamingServer([options]): creates a HTTP server ready for streaming yout webcams, the options are explained below (and are all optional)

  • streamWebcam([encoder]): return the promise of a Readable stream, defaults to avconv encodinf webm with realtime deadline

Given the flexibility of the API it should be easy to use webcams on the network or other types of realtime inputs, but keep in mind that the current implementation spawns one encoder per viewer (it was made for a tool where this limitation wasn't a problem).

Feel free to recommend me ways to overcome this difficulty :) i think that MPEG-2 with hsl.js or a similar lib may be a good way to start.

Complete API example

const webcam = require('webcam-http-streaming');

const encoder = {
  /*
   * encoder command or location
   *   Default: avconv
   */
  command: 'ffmpeg',
  /*
   * Function that returns the required flags, the video is expected to be
   * written to stdout
   *   Default: shown below
   */
  flags(webcam) {
    return `-f video4linux2 -i ${webcam} -f webm -deadline realtime pipe:1`;
  },
  /*
   * MIME type of the output stream
   *   Default: 'video/webm'
   */
  mimeType: 'video/webm',
  /*
   * Function that detects the success of the encoder process,
   * does cb(true) in case of succes, any other value for failure
   *
   * Calling cb more than one time has no effect
   *
   * encoderProcess is of type ChildProcess
   *
   *  Default: shown below, it isn't perfect but covers most of the cases
   */
  isSuccessful(encoderProcess, cb) {
    let started = false;
    encoderProcess.stderr.setEncoding('utf8');
    encoderProcess.stderr.on('data', (data) => {
      /* I trust that the output is line-buffered */
      const startedText = /Press ctrl-c to stop encoding/;
      if(startedText.test(data)) {
        cb(true);
        started = true;
      }
    });
    /* If the process start was not detected and it exited it's surely a failure */
    encoderProcess.on('exit', () => {
      if(!started) cb(false);
    });
  }
};

/* Suppose i want to use the default REST API */
const server = webcam.createHTTPStreamingServer({
  /*
   * Optional: A list of the permitted webcams, if it's specified overrides
   * isValidWebcam
   */
  permittedWebcams: ['/dev/video0', '/dev/video1'],
  /*
   * Validates if a given path is a valid webcam for use, the default is shown
   * below
   */
  isValidWebcam(webcam) {
    const webcamRegex = /\/dev\/video[0-9]+/;

    return new Promise((accept, reject) => {
      /* If doesn't seem like a video device block we will fail */
      if(!webcamRegex.test(webcam)) {
        reject(false);
      } else {
        /* ... and if the file doesn't exists */
        fileExists(webcam).then(accept, reject);
      }
    });
  }
  /*
   * The endpoint for requesting streams of the REST api
   *   Defaults to '/webcam'
   */
  webcamEndpoint: '/webcam',
  /*
   * Custom endpoints to extend the REST API
   *   req: [IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)
   *   res: [ServerResponse](https://nodejs.org/api/http.html#http_class_http_serverresponse)
   *   reqUrl: [URL Object](https://nodejs.org/api/url.html#url_url_strings_and_url_objects)
   *            with [QueryString](https://nodejs.org/api/querystring.html#querystring_querystring_parse_str_sep_eq_options)
   *
   * Note: the endpoint 'default' is used for any non-matching request
   */
  additionalEndpoints: {
    '/list_webcams': (req, res, reqUrl) => { res.end('<html>...</html>'); }
  },
  encoder: encoder
}).listen(8080);

/* Returns a promise that resolves to the video stream (stream.Readable) */
const videoStream = webcam.streamWebcam('/dev/video0', encoder);

Default REST API

  • /webcam?webcam=<webcam_device_block>: Returns a video/webm (by default, it can be changed) stream or an error (invalid_webcam, webcam_in_use by another process)

Errors

  • invalid_webcam: The webcam you requested hasn't been found or isn't in the list of permitted webcams
  {
    "code": "invalid_webcam",
    "error": "That webcam doesn't exist",
    "webcam": "/dev/video0"
  }
  • webcam_in_use: The webcam you requested was in use by another process
  {
    "code": "webcam_in_use",
    "error": "The webcam is already in use by another process",
    "webcam": "/dev/video0"
  }