Add Linux virtual camera output via v4l2loopback#4
Open
pubino wants to merge 1 commit into
Open
Conversation
Add --virtual-camera <device> (and --virtual-camera-pix-fmt) so streams can be written to a local v4l2loopback device and consumed by host apps — browsers, video conferencing, OBS, etc. — as a webcam source. Works for both browser/x11grab and --video-file inputs; ffmpeg switches to raw v4l2 output (no libx264, no audio) when the flag is set. --ingest is optional when --virtual-camera is provided. Linux-only; refuses to run elsewhere. Includes scripts/setup-virtual-camera.sh helper to load/unload the kernel module with sensible defaults, README docs, and tests covering CLI parsing, ffmpeg arg construction for both input modes, and platform/device guards.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--virtual-camera <device>(and--virtual-camera-pix-fmt) so page-stream can write to a Linux v4l2loopback device. The stream then appears as a webcam to any host app (Chromium/Firefox, Zoom, Meet, OBS, GStreamer, etc.).--video-fileinputs; ffmpeg branches to a raw v4l2 output (no libx264, no audio) when virtual-camera mode is on.--ingestis now optional when--virtual-camerais supplied. Health logs and reconnect/backoff machinery understand the v4l2 target.Includes:
scripts/setup-virtual-camera.sh— zsh-friendly helper to load/unloadv4l2loopbackwith sensible defaults (devices=1 video_nr=10 card_label=PageStream), plus--device/--label/--status/--teardown.ffplay -f v4l2 /dev/video10).tests/virtual-camera.test.tscovering CLI parsing, ffmpeg arg construction for both input modes, and platform/device guards.Test plan
Real-world local validation before merging to main:
sudo apt install v4l2loopback-dkmssudo ./scripts/setup-virtual-camera.sh(creates/dev/video10, labelPageStream)docker build -t page-stream:vc .(or run directly with locally-builtdist/)node dist/index.js --virtual-camera /dev/video10 --url demo/index.html --width 1280 --height 720 --fps 30ffplay -f v4l2 /dev/video10chromium --use-fake-ui-for-media-stream→ https://webcamtests.com (or any getUserMedia page) and pick "PageStream" from the camera listnode dist/index.js --virtual-camera /dev/video10 --video-file ./videos/loop.mp4 --video-loopnode dist/index.js --virtual-camera /dev/nonexistentshould exit with a clear error pointing atsetup-virtual-camera.shsudo ./scripts/setup-virtual-camera.sh --teardownAutomated tests (28 pass):
docker run --rm --entrypoint /bin/bash page-stream:vc -c "node --test --loader ts-node/esm tests/basic.test.ts tests/crop-infobar.test.ts tests/input-flags.test.ts tests/video-file.test.ts tests/virtual-camera.test.ts"Notes & follow-ups
--device /dev/video10:/dev/video10and is documented as such. Most users will run this on the host.