{"id":15886015,"url":"https://github.com/kybarg/camera","last_synced_at":"2026-04-29T18:31:15.199Z","repository":{"id":200552150,"uuid":"705756715","full_name":"kybarg/camera","owner":"kybarg","description":"Node.js Addons to work with web cameras","archived":false,"fork":false,"pushed_at":"2026-01-18T20:00:27.000Z","size":23239,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-19T03:51:43.265Z","etag":null,"topics":["camera","napi","node-addon-api","nodejs","web-camera","webcam","webcamera"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kybarg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-10-16T16:24:48.000Z","updated_at":"2026-01-18T20:00:31.000Z","dependencies_parsed_at":"2026-01-18T22:02:07.312Z","dependency_job_id":null,"html_url":"https://github.com/kybarg/camera","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"a83dc2905a5e161f0364467420a1bbd795eca878"},"previous_names":["kybarg/camera"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kybarg/camera","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kybarg%2Fcamera","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kybarg%2Fcamera/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kybarg%2Fcamera/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kybarg%2Fcamera/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kybarg","download_url":"https://codeload.github.com/kybarg/camera/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kybarg%2Fcamera/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32439084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T18:12:22.909Z","status":"ssl_error","status_checked_at":"2026-04-29T18:11:33.322Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["camera","napi","node-addon-api","nodejs","web-camera","webcam","webcamera"],"created_at":"2024-10-06T05:21:47.949Z","updated_at":"2026-04-29T18:31:15.194Z","avatar_url":"https://github.com/kybarg.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Camera Device Management Library\n\n[![npm version](https://img.shields.io/npm/v/@kybarg/camera.svg)](https://www.npmjs.com/package/@kybarg/camera)\n[![npm downloads](https://img.shields.io/npm/dm/@kybarg/camera.svg)](https://www.npmjs.com/package/@kybarg/camera)\n[![license](https://img.shields.io/github/license/kybarg/camera.svg)](LICENSE)\n[![github stars](https://img.shields.io/github/stars/kybarg/camera?style=social)](https://github.com/kybarg/camera)\n\nNode.js native addon for Windows camera capture using the Media Foundation API.\n\n## Highlights\n\n- Format selection: choose native subtypes such as `mjpeg`/`MJPEG`, `nv12`, `yuy2`, or supply a GUID string to target a specific media subtype.\n- `setFormat(format: CameraFormat)` is a single API: `format.subtype` (string or GUID), `width`, `height`, and a required `frameRate`.\n- Automatic recovery/resume support for device sleep or transient device loss (see `recoverDevice()` / `recoverDeviceAsync()` and `examples/recovery_test.js`).\n- Promise-based async API and TypeScript typings included.\n\n## Installation\n\n```powershell\nnpm install\nnpm run build\n```\n\nNotes: building the native addon requires Visual Studio Build Tools and Python (for `node-gyp`).\n\n## Quick Examples\n\n### JavaScript (minimal)\n\n```javascript\nconst Camera = require('@kybarg/camera');\n\nasync function main() {\n  const cam = new Camera();\n  const devices = await cam.enumerateDevices();\n  if (!devices.length) return console.log('No cameras');\n\n  await cam.claimDevice(devices[0].symbolicLink);\n\n  // Choose a supported format (eg. MJPEG or NV12) from getSupportedFormats()\n  const formats = await cam.getSupportedFormats();\n  // formats contain { subtype, width, height, frameRate, ... }\n  const fmt = formats.find(f =\u003e {\n    const s = (f.subtype || '').toLowerCase();\n    return s.includes('mjpeg') || s.includes('mjpg');\n  }) || formats[0];\n\n  await cam.setFormat({ subtype: fmt.subtype, width: fmt.width, height: fmt.height, frameRate: fmt.frameRate });\n\n  // Listen for raw sample buffers (Uint8Array-backed Buffer)\n  cam.on('frame', (buf) =\u003e {\n    console.log('frame bytes:', buf.length);\n    // buf is the raw contiguous sample bytes from the camera (MJPEG packet or NV12 plane data)\n  });\n\n  await cam.startCapture();\n\n  // stop later\n  setTimeout(async () =\u003e {\n    await cam.stopCapture();\n    await cam.releaseDevice();\n  }, 5000);\n}\n\nmain().catch(console.error);\n```\n\nImportant: the frames you receive are the native sample payloads. For compressed formats (MJPEG) the buffer contains JPEG frames. For planar formats (NV12) you'll get the raw plane data. The library intentionally avoids converting pixel formats automatically so you can control decoding/processing downstream.\n\n## API Overview\n\nAll async methods return Promises. See `index.d.ts` for full TypeScript types.\n\nCamera methods of interest:\n\n- `enumerateDevices(): Promise\u003cDeviceInfo[]\u003e` — list attached cameras with persistent `symbolicLink` identifiers.\n- `claimDevice(symbolicLink): Promise\u003cOperationResult\u003e` — claim exclusive use of a device (survives process restarts if claimed).\n- `releaseDevice(): Promise\u003cOperationResult\u003e` — release claimed device.\n- `getSupportedFormats(): Promise\u003cCameraFormat[]\u003e` — returns formats with fields `{ subtype, width, height, frameRate, guid? }`.\n- `setFormat(format: CameraFormat): Promise\u003cSetFormatResult\u003e` — set format using `subtype` (string like `nv12` or a GUID string), required `width`, `height`, and required `frameRate`.\n- `startCapture(): Promise\u003cOperationResult\u003e` — begin streaming; frames are emitted as `'frame'` events.\n- `stopCapture(): Promise\u003cOperationResult\u003e` — stop streaming.\n- `recoverDevice(): Promise\u003cOperationResult\u003e` — attempt to recover a previously-claimed device after sleep or transient loss; the native side will try small toggles and a recreate/restart before failing.\n- `isCapturing(): boolean` — synchronous check for capture state.\n\nEvents:\n\n- `'frame'` — emitted with a single argument: `Buffer` containing the raw sample bytes for that sample.\n\nExample TypeScript types (see `index.d.ts` in the repo):\n\n```ts\ninterface CameraFormat {\n  subtype: string; // human-friendly name (eg. 'nv12', 'mjpe g', 'yuy2') or GUID string\n  width: number;\n  height: number;\n  frameRate: number; // required\n}\n```\n\n## Recovery and Resume\n\nThe addon implements recovery helpers to improve robustness after system sleep or temporary device loss. `recoverDevice()` / `recoverDeviceAsync()` will attempt:\n\n1. a stream toggle (end session, short wait, restart) with a longer wait for the first sample;\n2. if that fails, a full recreate of the capture object and a restart attempt;\n3. it reports operation-level HRESULTs and diagnostic logs to stderr when enabled in the native build.\n\nSee `examples/recovery_test.js` for an automated test harness that triggers recovery on inactivity and validates whether frames resume.\n\n## Examples and Tests\n\nRun the examples:\n\n```powershell\nnpm run example\n# or\nnode examples/example.js\n\n# recovery test (non-interactive)\nnode examples/recovery_test.js\n```\n\n## Building\n\n```powershell\nnpm install\nnpm run build\n```\n\nRequirements: Windows 10/11, Visual Studio Build Tools (or VS), Python 3.x for node-gyp.\n\n## Notes\n\n- The library delivers raw sample buffers. If you need decoded RGBA frames, decode MJPEG or convert NV12 -\u003e RGBA using your preferred native or JS library (for example `sharp` for JPEG decoding or a native fast converter for NV12).\n- The `setFormat` API now accepts subtype names and GUID strings; for best results use a format object returned by `getSupportedFormats()`.\n\n## License\n\nSee [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkybarg%2Fcamera","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkybarg%2Fcamera","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkybarg%2Fcamera/lists"}