picamera.exc.PiCameraRuntimeError: Timed out waiting for capture to end
Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1704, in capture_continuous 'Timed out waiting for capture to end') picamera.exc.PiCameraRuntimeError: Timed out waiting for capture to end
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/usr/local/lib/python3.7/dist-packages/imutils/video/pivideostream.py", line 39, in update for f in self.stream: File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1710, in capture_continuous encoder.close() File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 431, in close self.stop() File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 419, in stop self._close_output() File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 349, in _close_output mo.close_stream(output, opened) File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 371, in close_stream stream.flush() File "/usr/lib/python3/dist-packages/picamera/array.py", line 238, in flush self.array = bytes_to_rgb(self.getvalue(), self.size or self.camera.resolution) File "/usr/lib/python3/dist-packages/picamera/array.py", line 127, in bytes_to_rgb 'Incorrect buffer length for resolution %dx%d' % (width, height)) picamera.exc.PiCameraValueError: Incorrect buffer length for resolution 1920x1080
I have encountered this quite a lot. I haven't found very much else on this subject covered by anyone. The problem happens after the camera has been running for a few days. Sometimes I can get the camera to run for a week. But not much more. The problem at this point is that you have to stop running Python and restart to get it going again.
If you take a look at the file where you are getting it - camera.py - Line 1704 (now 1717) you will see the error is raised when it doesn't get the frame within the timeout. After the encoder.start(output), if calls the "wait" function with the CAPTURE_TIMEOUT. If it doesn't receive a frame within that time, it raises the error. It is just a bit of a fatal error.
We need a bit more of an elegant resolution here. We can expect the camera to not respond at some point to the request to prepare a frame. In this case, can we return either an empty frame, or the last frame?