Skip to content

Add get_frame and get_frame_bytes for single screenshots - #61

Closed
antoniovazquezblanco wants to merge 1 commit into
puddly:devfrom
antoniovazquezblanco:single-frame
Closed

antoniovazquezblanco wants to merge 1 commit into
puddly:devfrom
antoniovazquezblanco:single-frame

Conversation

@antoniovazquezblanco

Copy link
Copy Markdown
Contributor

The MJPEG streams wait for frames indefinitely, so a screenshot taken without a video signal never returns. get_frame_bytes() returns one raw JPEG frame and get_frame() the decoded image; both close the stream once the frame arrives and raise TimeoutError when none arrives within timeout seconds (10 by default). A stream that ends before any frame raises NanoKVMInvalidResponseError.

The MJPEG streams wait for frames indefinitely, so a screenshot taken
without a video signal never returns. get_frame_bytes() returns one raw
JPEG frame and get_frame() the decoded image; both close the stream once
the frame arrives and raise TimeoutError when none arrives within
`timeout` seconds (10 by default). A stream that ends before any frame
raises NanoKVMInvalidResponseError.
@chiconws

Copy link
Copy Markdown
Collaborator

Thanks for this, and sorry for the overlap. #65 landed get_snapshot() on dev, which covers the same case: one raw JPEG frame from the MJPEG stream, with a timeout (20 s), the stream closed after the frame, and an error when the stream ends without one.

One deliberate difference: get_snapshot() refuses the Pro. On the Pro, MJPEG and H.264 share one encoder mode, so opening the MJPEG stream interrupts any WebRTC session (sipeed/NanoKVM-Pro#157). Merging get_frame_bytes() as-is would reopen that path.

I'm closing this as superseded. A few ideas from it are worth keeping, and I'll carry them over to get_snapshot():

  • raising NanoKVMInvalidResponseError when the stream ends without a frame
  • replacing the mjpeg_stream + break examples in the README and docs/sync.md with the snapshot call

Thanks again for the careful tests.

@chiconws chiconws closed this Oct 30, 2026
chiconws added a commit that referenced this pull request Oct 30, 2026
…ot in examples (#68)

* Raise NanoKVMInvalidResponseError for empty snapshots, use get_snapshot in examples

get_snapshot() raised the base NanoKVMError when the MJPEG stream ended
before any frame; it now raises NanoKVMInvalidResponseError, a subclass,
so existing handlers still catch it. The README and blocking-client
examples save a screenshot with get_snapshot() instead of breaking out
of a stream loop.

Both come from #61.

Co-authored-by: Antonio Vázquez Blanco <[email protected]>

* Allow snapshots on the Pro with interrupt_webrtc=True

get_snapshot() refused the Pro outright, because opening MJPEG there
ends any WebRTC session in progress. Callers that know no session is
open, or accept losing it, can now pass interrupt_webrtc=True. Without
it the Pro still refuses, and the error names the flag.

Measured on a Pro 1.2.15: the interrupted session raises
NanoKVMVideoModeError and does not recover, while a session started
after the snapshot gets video without changing the stream mode.

---------

Co-authored-by: Antonio Vázquez Blanco <[email protected]>
@antoniovazquezblanco
antoniovazquezblanco deleted the single-frame branch October 30, 2026 07:23
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