From 6cb05626544b2b3a5ad94669cb7d8fd8835dd4ba Mon Sep 17 00:00:00 2001 From: nandithebull Date: Sat, 28 Nov 2026 19:28:05 -0800 Subject: [PATCH] Camera: fix VFR video timestamps and close ffmpeg stderr - Pass -enc_time_base demux to ffmpeg so VFR video keeps the source timing - Read the encoder's stderr only on failure, and always close the pipe - Mirror the same ffmpeg flag and stderr close in test_camera.py --- camera/chandra-camera | 17 +++++++++++++---- camera/test_camera.py | 2 ++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/camera/chandra-camera b/camera/chandra-camera index b50dfed..d8e2fa2 100755 --- a/camera/chandra-camera +++ b/camera/chandra-camera @@ -2019,6 +2019,8 @@ class CameraEngine: "-", "-fps_mode", "passthrough", + "-enc_time_base", + "demux", "-video_track_timescale", "1000", "-c:v", @@ -2163,10 +2165,17 @@ class CameraEngine: if wt is not None: wt.join(timeout=15.0) rc = proc.wait(timeout=15.0) - if rc != 0 and proc.stderr is not None: - err = proc.stderr.read().decode("utf-8", "replace").strip() - if err and self.on_error: - self.on_error("Video encode error: " + err) + if proc.stderr is not None: + try: + if rc != 0: + err = proc.stderr.read().decode("utf-8", "replace").strip() + if err and self.on_error: + self.on_error("Video encode error: " + err) + finally: + try: + proc.stderr.close() + except Exception: + pass return path, frames diff --git a/camera/test_camera.py b/camera/test_camera.py index bf8ebef..0e1a326 100644 --- a/camera/test_camera.py +++ b/camera/test_camera.py @@ -304,6 +304,7 @@ class TestCameraHelpers(unittest.TestCase): "ffmpeg", "-y", "-loglevel", "error", "-f", "matroska", "-i", "-", "-fps_mode", "passthrough", + "-enc_time_base", "demux", "-video_track_timescale", "1000", "-c:v", "libx264", "-preset", "superfast", "-crf", "22", "-bf", "0", "-pix_fmt", "yuv420p", @@ -315,6 +316,7 @@ class TestCameraHelpers(unittest.TestCase): proc.stdin.close() rc = proc.wait(timeout=15) err = proc.stderr.read().decode("utf-8", "replace") + proc.stderr.close() self.assertEqual(rc, 0, msg="ffmpeg failed: " + err) info = json.loads(subprocess.check_output([