Skip to content

feat(webcam): Implement threaded streaming for high FPS#2

Open
cardil wants to merge 2 commits into
AGG2017:masterfrom
cardil:feature/speedy-webcam
Open

feat(webcam): Implement threaded streaming for high FPS#2
cardil wants to merge 2 commits into
AGG2017:masterfrom
cardil:feature/speedy-webcam

Conversation

@cardil
Copy link
Copy Markdown

@cardil cardil commented Nov 7, 2025

Overhauls the webcam functionality to provide a much smoother, higher frame-rate live stream.

Previously, each request for cam.jpg would open the camera device, capture a single frame, and then close the device. This process was extremely slow, resulting in a frame rate of less than 1 FPS and causing unnecessary wear on the flash storage.

The new implementation introduces a background thread for continuous capture:

  • A dedicated pthread is spawned on the first request to the webcam page.
  • This thread keeps the camera device open and continuously captures frames into /tmp/cam.jpg (a RAM disk), significantly reducing latency and eliminating flash writes.
  • The thread automatically terminates and releases the camera if no new web requests are received within a 2-second timeout.
  • The frontend refresh interval has been reduced from 2000ms to 125ms, enabling a frame rate of ~8 FPS.

To support this new model, the webcam C API was refactored:

  • v_capture_image is replaced by v_open_camera, v_capture_frame_to_file, and v_close_camera for more granular control over the device state.

This commit completely overhauls the webcam functionality to provide a much smoother, higher frame-rate live stream.

Previously, each request for `cam.jpg` would open the camera device, capture a single frame, and then close the device. This process was extremely slow, resulting in a frame rate of less than 1 FPS and causing unnecessary wear on the flash storage.

The new implementation introduces a background thread for continuous capture:

-   A dedicated pthread is spawned on the first request to the webcam page.
-   This thread keeps the camera device open and continuously captures frames into `/tmp/cam.jpg` (a RAM disk), significantly reducing latency and eliminating flash writes.
-   The thread automatically terminates and releases the camera if no new web requests are received within a 2-second timeout.
-   The frontend refresh interval has been reduced from 2000ms to 125ms, enabling a frame rate of ~8 FPS.

To support this new model, the webcam C API was refactored:
-   `v_capture_image` is replaced by `v_open_camera`, `v_capture_frame_to_file`, and `v_close_camera` for more granular control over the device state.

Additionally, a minor fix was made to the config parser to include the file path in the "cannot read" error message.
@cardil
Copy link
Copy Markdown
Author

cardil commented Feb 22, 2026

This is now integrated cardil#1

BTW. There's a major overhaul merged: cardil#2

@AGG2017
Copy link
Copy Markdown
Owner

AGG2017 commented Jun 1, 2026

Thanks for the contribution! This project is no longer a priority and it is used exactly as it was designed to be used: when the printer is in the basement from time to time to see visually if there is a printing issue and when the print is done. Never needed more than 1fps because we experienced a lot of issues with complex print jobs when loading the CPU or using more than the minimum possible RAM. Only highly optimized minimal version was able to survive in parallel. We stopped many extension projects because of that weak hardware that is barely keep working with just printing in some cases. The same is for the resolution, limited to the minimum that is still good but not getting too much resources. But if someone reduces a lot of the print speed searching for quality prints, or use very simple print jobs, then yes, the frame rate (and/or the resolution) can be increased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants