Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 570a5a0

Browse files
committed
nanokvm: ignore stale frames
1 parent 359b4f2 commit 570a5a0

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

packages/jumpstarter-driver-nanokvm/jumpstarter_driver_nanokvm/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ class NanoKVMVideoClient(DriverClient):
1919
from the NanoKVM device.
2020
"""
2121

22-
def snapshot(self) -> Image.Image:
22+
def snapshot(self, skip_frames: int = 3) -> Image.Image:
2323
"""
2424
Get a snapshot image from the video stream
2525
2626
Returns:
2727
PIL Image object of the snapshot
2828
"""
29-
input_jpg_data = b64decode(self.call("snapshot"))
29+
input_jpg_data = b64decode(self.call("snapshot", skip_frames))
3030
return Image.open(io.BytesIO(input_jpg_data))
3131

3232
def cli(self):

packages/jumpstarter-driver-nanokvm/jumpstarter_driver_nanokvm/driver.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,21 @@ def close(self):
9292

9393
@export
9494
@with_reauth
95-
async def snapshot(self) -> str:
95+
async def snapshot(self, skip_frames: int = 3) -> str:
9696
"""
9797
Take a snapshot from the video stream
9898
9999
Returns:
100100
Base64 encoded JPEG image data
101101
"""
102102
client = await self._get_client()
103+
frame_count = 0
103104
async for frame in client.mjpeg_stream():
104-
# Get the first frame and return it
105+
frame_count += 1
106+
# Skip the first frames as it's normally stale
107+
if frame_count < skip_frames:
108+
continue
109+
# Return the second (fresh) frame
105110
buffer = BytesIO()
106111
frame.save(buffer, format="JPEG")
107112
data = buffer.getvalue()

packages/jumpstarter-driver-nanokvm/jumpstarter_driver_nanokvm/driver_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def mock_nanokvm_client():
3232
test_image = Image.new("RGB", (640, 480), color="red")
3333

3434
async def mock_stream():
35+
# Yield several frames - first ones are buffered/old, later ones are fresh
36+
yield test_image
37+
yield test_image
38+
yield test_image
3539
yield test_image
3640

3741
mock_client.mjpeg_stream = mock_stream

0 commit comments

Comments
 (0)