-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebsocket_minicap.py
More file actions
45 lines (30 loc) · 1.11 KB
/
websocket_minicap.py
File metadata and controls
45 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Real-time screen streaming via WebSocket (minicap)."""
import asyncio
from devicebase import DeviceBaseClient
async def stream_screen():
"""Stream and display device screen frames."""
client = DeviceBaseClient(serial="device123")
# Use the high-level stream method
frame_count = 0
async for frame in client.stream_minicap():
# Save frame to file
with open(f"frame_{frame_count:04d}.jpg", "wb") as f:
f.write(frame)
frame_count += 1
if frame_count >= 10: # Capture 10 frames
break
print(f"Frame {frame_count}: {len(frame)} bytes")
print(f"Captured {frame_count} frames")
client.close()
async def capture_single():
"""Capture a single frame from the stream."""
client = DeviceBaseClient(serial="device123")
# Using minicap_client for more control
minicap = client.minicap_client()
frame = await minicap.capture_frame()
with open("capture.jpg", "wb") as f:
f.write(frame)
print(f"Captured: {len(frame)} bytes")
client.close()
if __name__ == "__main__":
asyncio.run(stream_screen())