From 9281f46bcd9b76e88f9e490f16c6677f8b5ca738 Mon Sep 17 00:00:00 2001 From: uvjustin <46082645+uvjustin@users.noreply.github.com> Date: Wed, 27 Apr 2022 03:36:09 -1000 Subject: [PATCH] Skip invalid segments in stream recorder (#70896) * Skip segment if duration is None * Copy segments deque before passing to thread --- homeassistant/components/stream/recorder.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/stream/recorder.py b/homeassistant/components/stream/recorder.py index 64a3208edcb..ae1c64396c8 100644 --- a/homeassistant/components/stream/recorder.py +++ b/homeassistant/components/stream/recorder.py @@ -60,6 +60,10 @@ def recorder_save_worker(file_out: str, segments: deque[Segment]) -> None: "r", format=SEGMENT_CONTAINER_FORMAT, ) + # Skip this segment if it doesn't have data + if source.duration is None: + source.close() + continue source_v = source.streams.video[0] source_a = source.streams.audio[0] if len(source.streams.audio) > 0 else None @@ -137,7 +141,7 @@ class RecorderOutput(StreamOutput): thread = threading.Thread( name="recorder_save_worker", target=recorder_save_worker, - args=(self.video_path, self._segments), + args=(self.video_path, self._segments.copy()), ) thread.start()