Pin debug replay to main recording stream (#24952)

* pin debug replay to one recording stream

Debug replay stream-copied the merged VOD playlist into one mp4. When main had gaps that sub filled, the clip switched streams mid-file, and a camera with an H.265 main and an H.264 sub produced an mp4 labeled H.264 that also held HEVC packets. The replay camera's decoder then failed and the watchdog killed ffmpeg. Replay now follows the clip download rule: it pins the playlist to main and only falls back to sub when the range has no main recordings.

* choose the replay stream with the vod coverage resolver

Stream selection counted a main row that only touched the range, while the pinned playlist served nothing for it, so replay failed instead of using the sub footage. Selection now uses resolve_coverage, the same resolver the pinned vod and export use.
This commit is contained in:
Josh Hawkins
2026-11-12 08:33:33 -07:00
committed by GitHub
parent 806ee66562
commit a655ddcb2e
3 changed files with 81 additions and 64 deletions
+41 -25
View File
@@ -18,6 +18,7 @@ from frigate.jobs.debug_replay import (
from frigate.jobs.export import JobStatePublisher
from frigate.jobs.manager import _completed_jobs, _current_jobs
from frigate.types import JobStatusTypesEnum
from frigate.util.recording_coverage import CoverageInterval
def _reset_job_manager() -> None:
@@ -77,6 +78,31 @@ class TestDebugReplayJob(unittest.TestCase):
self.assertEqual(results["end_ts"], 200.0)
class TestRecordingDebugReplaySource(unittest.TestCase):
def _source_url(self, intervals: list[CoverageInterval]) -> str:
source = RecordingDebugReplaySource(
source_camera="front", start_ts=100.0, end_ts=200.0, internal_port=5000
)
with patch(
"frigate.jobs.debug_replay.resolve_coverage", return_value=intervals
):
source.validate()
return source.ffmpeg_input_args("/tmp")[-1]
def test_pins_main_when_main_has_recordings(self) -> None:
url = self._source_url(
[
CoverageInterval(100.0, 150.0, None, MagicMock()),
CoverageInterval(150.0, 200.0, MagicMock(), MagicMock()),
]
)
self.assertIn("/vod/front/main/start/100.0/end/200.0/", url)
def test_falls_back_to_sub_without_main_recordings(self) -> None:
url = self._source_url([CoverageInterval(100.0, 200.0, None, MagicMock())])
self.assertIn("/vod/front/sub/start/100.0/end/200.0/", url)
class TestStartDebugReplayJob(unittest.TestCase):
def setUp(self) -> None:
_reset_job_manager()
@@ -87,9 +113,7 @@ class TestStartDebugReplayJob(unittest.TestCase):
self.frigate_config.ffmpeg.ffmpeg_path = "/bin/true"
self.publisher = MagicMock()
self.recordings_qs = MagicMock()
self.recordings_qs.count.return_value = 1
self.recordings_qs.__iter__.return_value = iter([MagicMock(path="/tmp/r1.mp4")])
self.coverage = [CoverageInterval(100.0, 200.0, MagicMock(), None)]
def tearDown(self) -> None:
runner = get_active_runner()
@@ -127,9 +151,7 @@ class TestStartDebugReplayJob(unittest.TestCase):
)
def test_rejects_when_no_recordings(self) -> None:
empty_qs = MagicMock()
empty_qs.count.return_value = 0
with patch("frigate.jobs.debug_replay.query_recordings", return_value=empty_qs):
with patch("frigate.jobs.debug_replay.resolve_coverage", return_value=[]):
with self.assertRaises(NoRecordingsError):
start_debug_replay_job(
source=RecordingDebugReplaySource(
@@ -152,8 +174,8 @@ class TestStartDebugReplayJob(unittest.TestCase):
with (
patch(
"frigate.jobs.debug_replay.query_recordings",
return_value=self.recordings_qs,
"frigate.jobs.debug_replay.resolve_coverage",
return_value=self.coverage,
),
patch(
"frigate.jobs.debug_replay.run_ffmpeg_with_progress",
@@ -192,8 +214,8 @@ class TestStartDebugReplayJob(unittest.TestCase):
with (
patch(
"frigate.jobs.debug_replay.query_recordings",
return_value=self.recordings_qs,
"frigate.jobs.debug_replay.resolve_coverage",
return_value=self.coverage,
),
patch(
"frigate.jobs.debug_replay.run_ffmpeg_with_progress",
@@ -242,9 +264,7 @@ class TestRunnerHappyPath(unittest.TestCase):
self.frigate_config.ffmpeg.ffmpeg_path = "/bin/true"
self.publisher = MagicMock()
self.recordings_qs = MagicMock()
self.recordings_qs.count.return_value = 1
self.recordings_qs.__iter__.return_value = iter([MagicMock(path="/tmp/r1.mp4")])
self.coverage = [CoverageInterval(100.0, 200.0, MagicMock(), None)]
def tearDown(self) -> None:
runner = get_active_runner()
@@ -272,8 +292,8 @@ class TestRunnerHappyPath(unittest.TestCase):
with (
patch(
"frigate.jobs.debug_replay.query_recordings",
return_value=self.recordings_qs,
"frigate.jobs.debug_replay.resolve_coverage",
return_value=self.coverage,
),
patch(
"frigate.jobs.debug_replay.run_ffmpeg_with_progress",
@@ -325,9 +345,7 @@ class TestRunnerFailurePath(unittest.TestCase):
self.frigate_config.cameras = {"front": MagicMock()}
self.frigate_config.ffmpeg.ffmpeg_path = "/bin/true"
self.publisher = MagicMock()
self.recordings_qs = MagicMock()
self.recordings_qs.count.return_value = 1
self.recordings_qs.__iter__.return_value = iter([MagicMock(path="/tmp/r1.mp4")])
self.coverage = [CoverageInterval(100.0, 200.0, MagicMock(), None)]
def tearDown(self) -> None:
runner = get_active_runner()
@@ -350,8 +368,8 @@ class TestRunnerFailurePath(unittest.TestCase):
with (
patch(
"frigate.jobs.debug_replay.query_recordings",
return_value=self.recordings_qs,
"frigate.jobs.debug_replay.resolve_coverage",
return_value=self.coverage,
),
patch(
"frigate.jobs.debug_replay.run_ffmpeg_with_progress",
@@ -399,9 +417,7 @@ class TestRunnerCancellation(unittest.TestCase):
self.frigate_config.cameras = {"front": MagicMock()}
self.frigate_config.ffmpeg.ffmpeg_path = "/bin/true"
self.publisher = MagicMock()
self.recordings_qs = MagicMock()
self.recordings_qs.count.return_value = 1
self.recordings_qs.__iter__.return_value = iter([MagicMock(path="/tmp/r1.mp4")])
self.coverage = [CoverageInterval(100.0, 200.0, MagicMock(), None)]
def tearDown(self) -> None:
runner = get_active_runner()
@@ -431,8 +447,8 @@ class TestRunnerCancellation(unittest.TestCase):
with (
patch(
"frigate.jobs.debug_replay.query_recordings",
return_value=self.recordings_qs,
"frigate.jobs.debug_replay.resolve_coverage",
return_value=self.coverage,
),
patch(
"frigate.jobs.debug_replay.run_ffmpeg_with_progress",