From 11163a69b6e88ae2daf651006136522b1d22083c Mon Sep 17 00:00:00 2001 From: chrisruk Date: Wed, 22 Jul 2020 11:37:07 +0100 Subject: [PATCH 1/3] use small preview buffer when out of resources --- picamera/camera.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/picamera/camera.py b/picamera/camera.py index 36b1202a..7fa0f9f1 100644 --- a/picamera/camera.py +++ b/picamera/camera.py @@ -2232,7 +2232,7 @@ def _get_config(self): colorspace=self._camera.outputs[0].colorspace ) - def _configure_camera(self, old, new): + def _configure_camera(self, old, new, small_preview=False): """ An internal method for setting a new camera mode, framerate, resolution, clock_mode, and/or ISP blocks. @@ -2304,13 +2304,19 @@ def _configure_camera(self, old, new): cc.max_stills_h = new.resolution.height cc.stills_yuv422 = 0 cc.one_shot_stills = 1 - cc.max_preview_video_w = new.resolution.width - cc.max_preview_video_h = new.resolution.height + if small_preview: + cc.max_preview_video_w = 1920 + cc.max_preview_video_h = 1080 + else: + cc.max_preview_video_w = new.resolution.width + cc.max_preview_video_h = new.resolution.height cc.num_preview_video_frames = max(3, fps_high // 10) cc.stills_capture_circular_buffer_height = 0 cc.fast_preview_resume = 0 cc.use_stc_timestamp = new.clock_mode self._camera.control.params[mmal.MMAL_PARAMETER_CAMERA_CONFIG] = cc + if small_preview: + preview_resolution = mo.to_resolution((1920,1080)) # Clamp preview resolution to camera's resolution if ( @@ -2613,9 +2619,14 @@ def _set_resolution(self, value): "Invalid resolution requested: %r" % (value,)) config = self._get_config() self._disable_camera() - self._configure_camera(config, config._replace(resolution=value)) - self._configure_splitter() - self._enable_camera() + try: + self._configure_camera(config, config._replace(resolution=value)) + self._configure_splitter() + self._enable_camera() + except PiCameraMMALError: + self._configure_camera(config, config._replace(resolution=value), small_preview=True) + self._configure_splitter() + self._enable_camera() resolution = property(_get_resolution, _set_resolution, doc=""" Retrieves or sets the resolution at which image captures, video recordings, and previews will be captured. From 6aa42177df726e90afa0a281b3641290e82f8cda Mon Sep 17 00:00:00 2001 From: chrisruk Date: Tue, 28 Jul 2020 11:21:37 +0100 Subject: [PATCH 2/3] Use smaller preview buffer size, for 76MB GPU RAM --- picamera/camera.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/picamera/camera.py b/picamera/camera.py index 7fa0f9f1..2599e8f5 100644 --- a/picamera/camera.py +++ b/picamera/camera.py @@ -2305,8 +2305,8 @@ def _configure_camera(self, old, new, small_preview=False): cc.stills_yuv422 = 0 cc.one_shot_stills = 1 if small_preview: - cc.max_preview_video_w = 1920 - cc.max_preview_video_h = 1080 + cc.max_preview_video_w = 320 + cc.max_preview_video_h = 240 else: cc.max_preview_video_w = new.resolution.width cc.max_preview_video_h = new.resolution.height @@ -2316,7 +2316,7 @@ def _configure_camera(self, old, new, small_preview=False): cc.use_stc_timestamp = new.clock_mode self._camera.control.params[mmal.MMAL_PARAMETER_CAMERA_CONFIG] = cc if small_preview: - preview_resolution = mo.to_resolution((1920,1080)) + preview_resolution = mo.to_resolution((320,240)) # Clamp preview resolution to camera's resolution if ( From 87021ea9537fd50d659eed078290682e06001752 Mon Sep 17 00:00:00 2001 From: chrisruk Date: Thu, 6 Aug 2020 10:04:37 +0100 Subject: [PATCH 3/3] Switch small preview resolution to 1080p --- picamera/camera.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/picamera/camera.py b/picamera/camera.py index 2599e8f5..7fa0f9f1 100644 --- a/picamera/camera.py +++ b/picamera/camera.py @@ -2305,8 +2305,8 @@ def _configure_camera(self, old, new, small_preview=False): cc.stills_yuv422 = 0 cc.one_shot_stills = 1 if small_preview: - cc.max_preview_video_w = 320 - cc.max_preview_video_h = 240 + cc.max_preview_video_w = 1920 + cc.max_preview_video_h = 1080 else: cc.max_preview_video_w = new.resolution.width cc.max_preview_video_h = new.resolution.height @@ -2316,7 +2316,7 @@ def _configure_camera(self, old, new, small_preview=False): cc.use_stc_timestamp = new.clock_mode self._camera.control.params[mmal.MMAL_PARAMETER_CAMERA_CONFIG] = cc if small_preview: - preview_resolution = mo.to_resolution((320,240)) + preview_resolution = mo.to_resolution((1920,1080)) # Clamp preview resolution to camera's resolution if (