def cmd_info(
ctx: typer.Context,
camera_name: Annotated[
Optional[CameraName], # noqa
typer.Option(
help="Name of the camera (all if not specified)",
envvar="CAMERA_NAME",
),
] = None,
camera_codec: Annotated[
VideoCodec,
typer.Option(
help="Camera video codec",
envvar="CAMERA_CODEC",
),
] = VideoCodec.yuyv.name,
camera_width: Annotated[
int,
typer.Option(
help="Camera frame width",
envvar="CAMERA_WIDTH",
),
] = 640,
camera_height: Annotated[
int,
typer.Option(
help="Camera frame height",
envvar="CAMERA_HEIGHT",
),
] = 480,
):
"""Get properties of connected cameras"""
obj = ctx.ensure_object(dict)
debug = obj.get("debug", False)
if debug:
v4l2py.device.log.setLevel(logging.DEBUG)
else:
v4l2py.device.log.setLevel(logging.INFO)
if camera_name:
if not Path(camera_name.val).exists():
logger.error(f"Camera not found: {camera_name}")
return
device = v4l2py.Device(camera_name.val)
try:
device.open()
except OSError:
logger.error(f"Failed to open {camera_name.val}")
return
print_device_info(device)
device.close()
show_stream(camera_name, camera_codec, camera_width, camera_height)
return
for device in v4l2py.iter_video_capture_devices():
try:
device.open()
except OSError:
pass
else:
print_device_info(device)
device.close()
print()