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,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