Hendrik Langer
4 years ago
2 changed files with 47 additions and 1 deletions
@ -0,0 +1,46 @@ |
|||
import io |
|||
import time |
|||
import picamera |
|||
from .base_camera import BaseCamera |
|||
|
|||
from threading import Condition |
|||
|
|||
class StreamingOutput(object): |
|||
def __init__(self): |
|||
self.frame = None |
|||
self.buffer = io.BytesIO() |
|||
self.condition = Condition() |
|||
|
|||
def write(self, buf): |
|||
if buf.startswith(b'\xff\xd8'): |
|||
# New frame, copy the existing buffer's content and notify all |
|||
# clients it's available |
|||
self.buffer.truncate() |
|||
with self.condition: |
|||
self.frame = self.buffer.getvalue() |
|||
self.condition.notify_all() |
|||
self.buffer.seek(0) |
|||
return self.buffer.write(buf) |
|||
|
|||
|
|||
class Camera(BaseCamera): |
|||
@staticmethod |
|||
def frames(): |
|||
with picamera.PiCamera() as camera: |
|||
camera.resolution = (640, 480) |
|||
camera.exposure_mode = 'sports' |
|||
camera.framerate = 15 |
|||
camera.rotation = 180 |
|||
# let camera warm up |
|||
time.sleep(2) |
|||
|
|||
output = StreamingOutput() |
|||
camera.start_recording(output, format='mjpeg') |
|||
|
|||
while True: |
|||
with output.condition: |
|||
output.condition.wait() |
|||
frame = output.frame |
|||
#yield b'--FRAME\r\n' |
|||
yield frame |
|||
#yield b'\r\n' |
Loading…
Reference in new issue