embeded stream opengl
This commit is contained in:
@@ -75,6 +75,20 @@ class StreamManager:
|
||||
log.info("Recorder started: pid=%s url=%s", proc.pid, self.stream_url)
|
||||
self._start_stderr_reader("recorder", proc)
|
||||
|
||||
def start_receiver_pipe(self):
|
||||
"""Receive stream, pipe stdout to mpv, save segments to disk."""
|
||||
self.setup_dirs()
|
||||
node = ff.receive_to_pipe(
|
||||
self.stream_url,
|
||||
segment_dir=self.stream_dir,
|
||||
segment_duration=SEGMENT_DURATION,
|
||||
)
|
||||
proc = ff.run_async(node, pipe_stdout=True, pipe_stderr=True)
|
||||
self._procs["receiver"] = proc
|
||||
log.info("Receiver started: pid=%s url=%s (pipe + segments)", proc.pid, self.stream_url)
|
||||
self._start_stderr_reader("receiver", proc)
|
||||
return proc
|
||||
|
||||
def start_recorder_with_monitor(self):
|
||||
self.setup_dirs()
|
||||
fifo_path = self.session_dir / "monitor.pipe"
|
||||
@@ -104,6 +118,30 @@ class StreamManager:
|
||||
t = Thread(target=_read, daemon=True, name=f"{name}_stderr")
|
||||
t.start()
|
||||
|
||||
def start_frame_extractor_on_recording(self, recording_path):
|
||||
"""Extract frames periodically from a growing recording file."""
|
||||
log.info("Starting frame extractor on recording: %s", recording_path)
|
||||
self._recording_path = recording_path
|
||||
self._start_recording_frame_watcher()
|
||||
|
||||
def _start_recording_frame_watcher(self):
|
||||
def _watch():
|
||||
last_size = 0
|
||||
log.info("Recording frame watcher running, watching %s", self._recording_path)
|
||||
while "stop" not in self._stop_flags:
|
||||
if self._recording_path.exists():
|
||||
size = self._recording_path.stat().st_size
|
||||
if size > last_size and size > 100_000: # wait for some data
|
||||
log.info("Recording grew: %d -> %d bytes, extracting frames", last_size, size)
|
||||
last_size = size
|
||||
self._extract_frames_from_file(self._recording_path)
|
||||
time.sleep(10) # check every 10s
|
||||
log.info("Recording frame watcher stopped")
|
||||
|
||||
t = Thread(target=_watch, daemon=True, name="recording_frame_watcher")
|
||||
t.start()
|
||||
self._threads["recording_frame_watcher"] = t
|
||||
|
||||
def start_frame_extractor(self):
|
||||
log.info("Starting frame watcher...")
|
||||
self._start_frame_watcher()
|
||||
|
||||
Reference in New Issue
Block a user