Skip to content

Commit ff30c25

Browse files
authored
Merge pull request #18 from srl-ethz/fix_streaming_docs
Fix streaming documentation to avoid laggy connection, add command line options to test_video_device.py
2 parents 89d94a8 + 829301f commit ff30c25

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Stream your robot's video feed, audio, and even MuJoCo simulations back to Visio
114114

115115
```python
116116
from avp_stream import VisionProStreamer
117+
from time import sleep
117118
avp_ip = "10.31.181.201" # Vision Pro IP (shown in the app)
118119
s = VisionProStreamer(ip = avp_ip)
119120

@@ -124,6 +125,7 @@ s.start_webrtc() # Start streaming to Vision Pro
124125
while True:
125126
r = s.latest
126127
print(r['head'], r['right_wrist'], r['right_fingers'])
128+
sleep(0.01) # avoid blocking the loop and let frames be sent
127129
```
128130

129131
**Example 1: Camera with custom processing:**
@@ -252,7 +254,8 @@ s.set_origin("sim") # Simulation's coordinate frame (relative to attach_to)
252254
**Note:** Finding the right combination of `device`, `format`, `size`, and `fps` can be tricky since cameras only support certain combinations. Use this script to find valid configurations:
253255

254256
```bash
255-
python test_video_devices.py --live
257+
python test_video_devices.py --live \
258+
--device /dev/video0 --format v4l2 --size 640x480 --fps 30
256259
```
257260

258261

test_video_device.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
Helps you find the right video_device, format, and options for your system.
55
66
Usage:
7+
# Override default camera settings
8+
python test_video_device.py --device /dev/video0 --format v4l2 --size 640x480 --fps 30
79
python test_video_device.py # Quick test (receive one frame)
810
python test_video_device.py --live # Live view (shows frames until Ctrl+C)
911
python test_video_device.py --save # Save 10 seconds of video
@@ -25,15 +27,14 @@ async def test_video_device(device, format="avfoundation", size="1280x720", fps=
2527
2628
Args:
2729
device: Device identifier (e.g., "0:none", "0", "/dev/video0")
28-
format_name: Format string (e.g., "avfoundation", "v4l2", "dshow")
29-
options: Dict of options (e.g., {"video_size": "640x480", "framerate": "30"})
30+
format: Format string (e.g., "avfoundation", "v4l2", "dshow")
31+
size: Video resolution as "WIDTHxHEIGHT" (e.g., "1280x720")
32+
fps: Frames per second (e.g., 30)
3033
mode: "test" (single frame), "live" (continuous display), or "save" (record video)
3134
3235
Returns:
3336
bool: True if device opens successfully, False otherwise
3437
"""
35-
if options is None:
36-
options = {}
3738

3839
print(f"\n{'='*60}")
3940
print(f"Testing: {device}")
@@ -121,11 +122,11 @@ def signal_handler(sig, frame):
121122

122123
# Initialize video writer
123124
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
124-
fps = int(options.get("framerate", "30"))
125-
video_writer = cv2.VideoWriter(output_file, fourcc, fps, (width, height))
126-
125+
writer_fps = int(fps)
126+
video_writer = cv2.VideoWriter(output_file, fourcc, writer_fps, (width, height))
127+
127128
print(f" Recording to: {output_file}")
128-
print(f" Resolution: {width}x{height} @ {fps}fps")
129+
print(f" Resolution: {width}x{height} @ {writer_fps}fps")
129130

130131
# Write first frame
131132
img = frame.to_ndarray(format="bgr24")
@@ -180,6 +181,28 @@ async def main():
180181
parser = argparse.ArgumentParser(
181182
description="Test video device configurations for VisionProStreamer"
182183
)
184+
parser.add_argument(
185+
"--device",
186+
default="0:none",
187+
help="Video device identifier (e.g., '/dev/video0', '0:none') (default: '0:none')"
188+
)
189+
parser.add_argument(
190+
"--format",
191+
dest="format_name",
192+
default="avfoundation",
193+
help="Input format string (e.g., 'v4l2', 'avfoundation', 'dshow') (default: 'avfoundation')"
194+
)
195+
parser.add_argument(
196+
"--size",
197+
default="1280x720",
198+
help="Resolution as WIDTHxHEIGHT (default 1280x720)"
199+
)
200+
parser.add_argument(
201+
"--fps",
202+
type=float,
203+
default=30,
204+
help="Frames per second (default 30)"
205+
)
183206
parser.add_argument(
184207
"--live",
185208
action="store_true",
@@ -200,12 +223,12 @@ async def main():
200223
mode = "save"
201224
else:
202225
mode = "test"
203-
226+
204227
await test_video_device(
205-
device="0:none",
206-
format="avfoundation",
207-
size="1280x720",
208-
fps=30,
228+
device=args.device,
229+
format=args.format_name,
230+
size=args.size,
231+
fps=args.fps,
209232
mode=mode
210233
)
211234

0 commit comments

Comments
 (0)