Skip to content

Commit

Permalink
Use FfmpegOutput as output
Browse files Browse the repository at this point in the history
  • Loading branch information
xeonqq committed Mar 13, 2024
1 parent 857abbd commit 1f46ae6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/camera_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
import time
import queue
import logging
from .tape import Tape
# from .tape import Tape
from picamera2.encoders import H264Encoder
from picamera2.outputs import FfmpegOutput

class StartEvent(object):
def execute(self, camera_recorder):
Expand All @@ -21,19 +22,28 @@ def __init__(self, camera, led, recording_folder, daemon=True):
self._folder.mkdir(parents=True, exist_ok=True)
self._camera = camera
self._led = led
self._format = "h264"
self._tape = Tape(self.fps, self._format)
# self._tape = Tape(self.fps, self._format)
self._is_recording = False
self._event_queue = queue.Queue()
self._encoder = H264Encoder(10000000)

filepath = "{}/recording_{}_%03d.mp4".format(
self._folder, time.strftime("%Y%m%d-%H%M%S")
)
ffmpeg_cmd = """-v 16 -framerate {0} -f {1}
-i pipe:0 -codec copy
-movflags faststart
-segment_time 00:01:00 -f segment -reset_timestamps 1
-y {2}""".format(
self.fps, "h264", filepath)
self._tape = FfmpegOutput(self._ffmpeg_cmd)
if daemon:
self._thread = threading.Thread(target=self.run, daemon=True)
self._thread.start()

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

def is_recording(self):
return self._is_recording
Expand All @@ -47,7 +57,7 @@ def stop(self):
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._tape.save_at(self._folder)
self._camera.start_recording(self._encoder, self._tape)
self._is_recording = True

Expand Down
4 changes: 4 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def main():
video_config = camera.create_video_configuration(main_stream, lores_stream, encode="main")
camera.configure(video_config)

camera.set_controls({"FrameRate": 20})
metadata = camera.capture_metadata()
print(metadata)

#camera.framerate = 20
#camera.exposure_mode = "sports"

Expand Down

0 comments on commit 1f46ae6

Please sign in to comment.