From 4f05fa29da3036e6197886cf9b9e743467d7822e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 16 Jun 2025 17:37:29 +0000 Subject: [PATCH] fix: Force AVFoundation for macOS camera, improve error clarity Modifies modules/video_capture.py to exclusively attempt using cv2.CAP_AVFOUNDATION for camera initialization on macOS. The fallback to the default backend for macOS within this specific initialization block has been removed. If AVFoundation fails to open the camera, an error is logged, and the subsequent standard check in the function will raise a RuntimeError, making it clearer that AVFoundation was the point of failure. This change aims to provide better diagnostics for macOS camera issues and ensure the intended AVFoundation backend is prioritized without immediate fallback to potentially problematic default backends like OBSENSOR. --- modules/video_capture.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/video_capture.py b/modules/video_capture.py index 5721212..cb101fc 100644 --- a/modules/video_capture.py +++ b/modules/video_capture.py @@ -51,14 +51,13 @@ class VideoCapturer: else: # Unix-like systems (Linux/Mac) capture method if platform.system() == "Darwin": # macOS - print("INFO: Attempting to use cv2.CAP_AVFOUNDATION for macOS camera.") + print(f"INFO: macOS detected. Attempting to use cv2.CAP_AVFOUNDATION exclusively for camera index {self.device_index}.") self.cap = cv2.VideoCapture(self.device_index, cv2.CAP_AVFOUNDATION) + # The check 'if not self.cap or not self.cap.isOpened():' later in the function + # will now directly reflect the success or failure of AVFoundation. if not self.cap or not self.cap.isOpened(): - print("WARN: cv2.CAP_AVFOUNDATION failed to open camera. Trying default backend for macOS.") - # Release the failed attempt before trying again - if self.cap: - self.cap.release() - self.cap = cv2.VideoCapture(self.device_index) # Fallback to default + print(f"ERROR: cv2.CAP_AVFOUNDATION failed to open camera index {self.device_index}. Capture will likely fail.") + # No fallback to default cv2.VideoCapture(self.device_index) here for macOS. else: # Other Unix-like systems (e.g., Linux) self.cap = cv2.VideoCapture(self.device_index)