44Helps you find the right video_device, format, and options for your system.
55
66Usage:
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,8 +27,9 @@ 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:
@@ -119,11 +122,11 @@ def signal_handler(sig, frame):
119122
120123 # Initialize video writer
121124 fourcc = cv2 .VideoWriter_fourcc (* 'mp4v' )
122- fps = int (options . get ( "framerate" , "30" ) )
123- video_writer = cv2 .VideoWriter (output_file , fourcc , fps , (width , height ))
124-
125+ writer_fps = int (fps )
126+ video_writer = cv2 .VideoWriter (output_file , fourcc , writer_fps , (width , height ))
127+
125128 print (f" Recording to: { output_file } " )
126- print (f" Resolution: { width } x{ height } @ { fps } fps" )
129+ print (f" Resolution: { width } x{ height } @ { writer_fps } fps" )
127130
128131 # Write first frame
129132 img = frame .to_ndarray (format = "bgr24" )
@@ -178,6 +181,28 @@ async def main():
178181 parser = argparse .ArgumentParser (
179182 description = "Test video device configurations for VisionProStreamer"
180183 )
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+ )
181206 parser .add_argument (
182207 "--live" ,
183208 action = "store_true" ,
@@ -198,12 +223,12 @@ async def main():
198223 mode = "save"
199224 else :
200225 mode = "test"
201-
226+
202227 await test_video_device (
203- device = "0:none" ,
204- format = "avfoundation" ,
205- size = "1280x720" ,
206- fps = 30 ,
228+ device = args . device ,
229+ format = args . format_name ,
230+ size = args . size ,
231+ fps = args . fps ,
207232 mode = mode
208233 )
209234
0 commit comments