Open stuartofmt opened 1 year ago
As a follow up ...
Based in this part of the error when using format : YUYV
KeyError: 'FrameDurationLimits'
I tried
config = picam2.create_video_configuration(main={"format" : "YUYV"},controls={'FrameRate': 25})
and
config = picam2.create_video_configuration(main={"format" : "YUYV"},controls={'FrameDurationLimits': (40000 , 40000)})
which resulted in:
Traceback (most recent call last):
File "/home/pi/videostream/./videostream-lite.py", line 106, in <module>
picam2.configure(config)
File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 1004, in configure
self.configure_(camera_config)
File "/usr/lib/python3/dist-packages/picamera2/picamera2.py", line 999, in configure_
self.controls = Controls(self, controls=self.camera_config['controls'])
File "/usr/lib/python3/dist-packages/picamera2/controls.py", line 24, in __init__
self.set_controls(controls)
File "/usr/lib/python3/dist-packages/picamera2/controls.py", line 58, in set_controls
self.__setattr__(k, v)
File "/usr/lib/python3/dist-packages/picamera2/controls.py", line 33, in __setattr__
raise RuntimeError(f"Control {name} is not advertised by libcamera")
RuntimeError: Control FrameDurationLimits is not advertised by libcamera
Hi, I'm afraid support for USB cameras is very limited, and there are no plans to extend support for them.
Understood. To what extent is there support for USB cameras?
I'm asking only so I don't go down a rabbit hole of investigation. I can (and have) handled USB cameras with openCV but was hoping to avoid that due to the various problems getting openCV to install on pi's of different stripes.
In other words - even experienced folks may have to try several techniques to get openCV installed. My program is aimed at inexperienced folks :-)
Probably what I'll do is create a "lite" version just for dedicated pi cameras.
I think the support extends to getting frames out of USB cameras, and displaying them in the slow (non-EGL accelerated) preview. I think you can save it as a JPEG as well (which obviously doesn't need to do an extra JPEG encode now). I use USB cams mostly for testing multi-camera functionality without requiring a compute module!
You can't do "video encode" so far as I know, though there's a chance you could make something work by tossing the JPEG frames at the base Encoder class, for which encode is a no-op. I suppose that might even allow you to stream them, though I don't think USB cams are sufficiently important to us to devote resources to that.
I recommend installing OpenCV from apt (sudo apt install python3-opencv, I think). I've had no end of trouble installing from other sources, where it goes off and spends a day compiling stuff and then failing at the final hurdle. I would install Qt from apt as well, otherwise it can assume a different version of OpenCV from what you have (if you didn't get OpenCV from apt). It's all a bit of a minefield.
Describe the bug Testing streaming of USB camera. Works with Pi camera but not USB. I realize that full support for USB may not be available, but it seems this is a straightforward use case that should work.
USB camera displays stills in preview with picam.create_preview_configuration({"format": "MJPEG"})
Pi camera works fine with: picam2.configure(picam2.create_video_configuration()) but not
picam2.configure(picam2.create_video_configuration({"format": "MJPEG"}))
USB camera throws an error: ValueError: Invalid format: MJPEG. Valid formats are: ...
This occures when attempting to capture video with either: picam2.configure(picam2.create_video_configuration()) or picam2.configure(picam2.create_video_configuration({"format": "MJPEG"}))
I tried YUYV (a valid format and reported by camera as available)
picam2.configure(picam2.create_video_configuration({"format": "YUYV"})) This gave a different error (see below)
To Reproduce This following sample code is taken from one of the examples with some added code to provide info about the cameras. All changes are at the end of the code.
Expected behaviour That it works :-) or maybe a workaround?
Console Output, Screenshots I added a few spaces to the console output for ease of reading.
I notice that the sensor.modes information from the pi camera (lots of it) is very different to that of the USB camera([{'format': 'MJPEG'}, {'format': 'YUYV'}]).
The output using picam2.configure(picam2.create_video_configuration()) or picam2.configure(picam2.create_video_configuration({"format": "MJPEG"}))
The error using picam2.configure(picam2.create_video_configuration({"format": "YUYV"}))
Hardware : Pi 3B+ Glamor enabled Bullseye 64