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
parent
4a390703be
commit
4f05fa29da
|
@ -51,14 +51,13 @@ class VideoCapturer:
|
||||||
else:
|
else:
|
||||||
# Unix-like systems (Linux/Mac) capture method
|
# Unix-like systems (Linux/Mac) capture method
|
||||||
if platform.system() == "Darwin": # macOS
|
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)
|
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():
|
if not self.cap or not self.cap.isOpened():
|
||||||
print("WARN: cv2.CAP_AVFOUNDATION failed to open camera. Trying default backend for macOS.")
|
print(f"ERROR: cv2.CAP_AVFOUNDATION failed to open camera index {self.device_index}. Capture will likely fail.")
|
||||||
# Release the failed attempt before trying again
|
# No fallback to default cv2.VideoCapture(self.device_index) here for macOS.
|
||||||
if self.cap:
|
|
||||||
self.cap.release()
|
|
||||||
self.cap = cv2.VideoCapture(self.device_index) # Fallback to default
|
|
||||||
else: # Other Unix-like systems (e.g., Linux)
|
else: # Other Unix-like systems (e.g., Linux)
|
||||||
self.cap = cv2.VideoCapture(self.device_index)
|
self.cap = cv2.VideoCapture(self.device_index)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue