Skip to content

Commit d9704ae

Browse files
committed
Harden frame rate handling in video recorder
Initialize FPS with a safe default, parse `frame_rate` defensively, and only warn/fallback when the configured value is missing or non-positive. This avoids startup failures from invalid frame-rate values while preserving expected logging. The commit also removes stale commented-out writer configuration code.
1 parent 8574e73 commit d9704ae

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

‎dlclivegui/services/video_recorder.py‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,20 @@ def start(self) -> None:
109109
self._queue = None
110110
self._writer_thread = None
111111

112-
if self._frame_rate and float(self._frame_rate) > 0.0:
113-
fps_value = float(self._frame_rate)
114-
else:
115-
fps_value = 30.0
116-
logger.warning(
117-
"VideoRecorder frame_rate missing/zero for %s; falling back to %.3f FPS. "
118-
"Video playback duration may not match capture timestamps.",
119-
self._output.name,
120-
fps_value,
121-
)
112+
fps_value = 30.0
113+
if self._frame_rate is not None:
114+
try:
115+
fps_value = float(self._frame_rate)
116+
except Exception:
117+
fps_value = 0.0
118+
if fps_value <= 0.0:
119+
fps_value = 30.0
120+
logger.warning(
121+
"VideoRecorder frame_rate missing/zero for %s; falling back to %.3f FPS. "
122+
"Video playback duration may not match capture timestamps.",
123+
self._output.name,
124+
fps_value,
125+
)
122126

123127
logger.info(
124128
"Starting VideoRecorder output=%s frame_size=%s frame_rate=%.3f "
@@ -139,15 +143,6 @@ def start(self) -> None:
139143
"-vcodec": (self._codec or "libx264").strip() or "libx264",
140144
"-crf": int(self._crf),
141145
}
142-
# if not self._convert_grayscale_to_rgb:
143-
# writer_kwargs.update(
144-
# {
145-
# "-pix_fmt": "yuv420p",
146-
# }
147-
# )
148-
# if self._frame_size is not None:
149-
# h, w = self._frame_size
150-
# writer_kwargs["-output_dimensions"] = (int(w), int(h))
151146

152147
self._output.parent.mkdir(parents=True, exist_ok=True)
153148
self._writer = WriteGear(output=str(self._output), **writer_kwargs)

0 commit comments

Comments
 (0)