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.
pull/1298/head
google-labs-jules[bot] 2025-06-16 17:37:29 +00:00
parent 4a390703be
commit 4f05fa29da
1 changed files with 5 additions and 6 deletions

View File

@ -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)