
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
camera-capture
Advanced tools
Super portable, fast camera capture library for node.js (server). TypeScript/JavaScript easy to use APIs. Uses puppeteer headless browser to capture webcam video (audio/desktop, recording, etc) and stream back to node.js frame by frame in plain image data
Portable Camera, audio, desktop capture Node.js library.
After searching for an easy to use portable library to access the webcam directly from node.js I didn't found a library that works in windows, macOs and linux, without native dependencies that users need ot manually install (or even so, they won't work).
This library solves the problem with an easy approach. Use headless browser to capture the video, draw in canvas and pass the image data the Node.js context as fast as possible (age.exposeFunction()) and with minimal processing. It uses HTMLCanvasElement getImageData when returning raw image data or HTMLCanvasElement.toBlob() when retuning encoded images such as png, jpg. In both cases using ArrayBuffer
npm install camera-capture puppeteer
(puppeteer is a peer dependency you must install it by yourself)
import {VideoCapture} from 'camera-capture'
const c = new VideoCapture()
c.addFrameListener(frame => {
// frame by default is unencoded raw Image Data `{width: 480, height: 320, data: UIntArray}``
// which is often what image processing / surfaces interfaces expect for fast processing.
// Use `mime` option to receive it in other formats (see examples below)
surface.putImageData(0,0,frame.width, frame.height, frame.data)
})
// pause / resume frame emission (without tunning off the camera)
setTimeout(()=>c.pause(), 1000)
setTimeout(()=>c.resume(), 2000)
// shutdown everything, including, camera, browser, server:
setTimeout(()=>c.stop(), 3000)
console.log('Capturing camera');
await c.start() // promise will be resolved only when `stop`
console.log('Stopping camera capture');
Instead of using start() and being notified on each frame, just call initialize() and read frames programmatically:
import {VideoCapture} from 'camera-capture'
const c = new VideoCapture({
mime: 'image/png'
})
await c.initialize()
let f = await c.readFrame() // PNG as configured
writeFileSync('tmp.png', f.data)
f = await c.readFrame('image/webp') // take another shot this time as webp image
writeFileSync('tmp.webp', f.data)
f = await c.readFrame('image/jpeg') // jpeg
writeFileSync('tmp.jpg', f.data)
f = await c.readFrame('rgba') // raw image data (as default)
writeFileSync('tmp-8bit-200x200.rgba', f.data)
The following uses DOM MediaRecorder API to record video. Notice that it all happens in the browser, on memory, so the result is a excellent quality video but it could consume lots of memory on long recordings. If that's an issue perhaps it's better to store frame by frame to hard drive and then use a video assembler like ffmpeg / imagemagick. (in the roadmap):
import {VideoCapture} from 'camera-capture'
const c = new VideoCapture({ port: 8082 })
await c.initialize()
await c.startRecording()
await sleep(500)
const data = await c.stopRecording()
writeFileSync('tmp6.webm', data)
TODO - TBD
I didn't found any library that provides an interface to capture webcam video so I show the video and filter frame by frame in my Node.s desktop app (not based on electron - no canvas / HTML5 available - rendering on cairo/opengl surface that complies with
Observed behavior:
About, 30 frames per second (size 600x400, format: raw image data)
FAQs
Super portable, fast camera capture library for node.js (server). TypeScript/JavaScript easy to use APIs. Uses puppeteer headless browser to capture webcam video (audio/desktop, recording, etc) and stream back to node.js frame by frame in plain image data
We found that camera-capture demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.