Skip to content

Commit

Permalink
Use picamera2 api in camera_recorder
Browse files Browse the repository at this point in the history
  • Loading branch information
xeonqq committed Mar 13, 2024
1 parent 13a4631 commit 857abbd
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/camera_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import queue
import logging
from .tape import Tape

from picamera2.encoders import H264Encoder

class StartEvent(object):
def execute(self, camera_recorder):
Expand All @@ -25,13 +25,15 @@ def __init__(self, camera, led, recording_folder, daemon=True):
self._tape = Tape(self.fps, self._format)
self._is_recording = False
self._event_queue = queue.Queue()
self._encoder = H264Encoder(10000000)

if daemon:
self._thread = threading.Thread(target=self.run, daemon=True)
self._thread.start()

@property
@property #fixme
def fps(self):
return self._camera.framerate
return 20 #self._camera.framerate

def is_recording(self):
return self._is_recording
Expand All @@ -46,7 +48,7 @@ def _start_recording(self):
if not self._is_recording:
logging.info("start recording, saving at {}".format(self._folder))
self._tape.save_at(self._folder)
self._camera.start_recording(self._tape, format=self._format)
self._camera.start_recording(self._encoder, self._tape)
self._is_recording = True

def _stop_recording(self):
Expand All @@ -66,13 +68,13 @@ def run(self, start_recording=True):
self._start_recording()
while True:
if self._is_recording:
self._camera.wait_recording(1)
self._led.toggle()
self.process_event()
else:
self._led.off()
# self._camera.wait_recording(1)
# self._led.toggle()
self.process_event()
time.sleep(0.05)
# else:
# self._led.off()
# self.process_event()
time.sleep(0.5)

def notify(self, event):
self._event_queue.put(event)

0 comments on commit 857abbd

Please sign in to comment.