From: Benjamin Braatz Date: Thu, 29 Jul 2021 14:18:45 +0000 (+0200) Subject: New stream per file. X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=5b5d7bfb03c73d3d6fb78edd36845eff16c73702;p=graphit%2Fcontrolpi-camera.git New stream per file. --- diff --git a/controlpi_plugins/camera.py b/controlpi_plugins/camera.py index 0e2790c..98fc608 100644 --- a/controlpi_plugins/camera.py +++ b/controlpi_plugins/camera.py @@ -57,7 +57,6 @@ class Camera(BasePlugin): async def run(self) -> None: """Run camera.""" camera = picamera.PiCamera() - stream = io.BytesIO() camera.resolution = self._resolution camera.iso = self._iso try: @@ -79,12 +78,14 @@ class Camera(BasePlugin): filepath = os.path.join(self.conf['path'], filename) await aiofiles.os.remove(filepath) + stream = io.BytesIO() camera.capture(stream, 'jpeg', resize=self._resize) filename = (datetime.datetime.utcnow() .strftime('%Y%m%d%H%M%S%f') + '.jpg') filepath = os.path.join(self.conf['path'], filename) async with aiofiles.open(filepath, 'wb') as f: await f.write(stream.getvalue()) + stream.close() self._images.append(filename) await self.bus.send(Message(self.name, {'event': 'new image',