refactor: enhance error handling and logging in RTSPReader for improved frame retrieval diagnostics
All checks were successful
Build Worker Base and Application Images / check-base-changes (push) Successful in 8s
Build Worker Base and Application Images / build-base (push) Has been skipped
Build Worker Base and Application Images / build-docker (push) Successful in 2m57s
Build Worker Base and Application Images / deploy-stack (push) Successful in 20s
All checks were successful
Build Worker Base and Application Images / check-base-changes (push) Successful in 8s
Build Worker Base and Application Images / build-base (push) Has been skipped
Build Worker Base and Application Images / build-docker (push) Successful in 2m57s
Build Worker Base and Application Images / deploy-stack (push) Successful in 20s
This commit is contained in:
parent
65b7573fed
commit
08cb4eafc4
1 changed files with 12 additions and 6 deletions
|
@ -90,24 +90,30 @@ class RTSPReader:
|
||||||
|
|
||||||
# Read frame immediately without rate limiting for minimum latency
|
# Read frame immediately without rate limiting for minimum latency
|
||||||
try:
|
try:
|
||||||
ret, frame = self.cap.read()
|
# Force grab then retrieve for better error handling
|
||||||
|
ret = self.cap.grab()
|
||||||
|
if ret:
|
||||||
|
ret, frame = self.cap.retrieve()
|
||||||
|
else:
|
||||||
|
frame = None
|
||||||
except Exception as read_error:
|
except Exception as read_error:
|
||||||
logger.error(f"Camera {self.camera_id}: cap.read() threw exception: {type(read_error).__name__}: {read_error}")
|
logger.error(f"Camera {self.camera_id}: cap.grab/retrieve threw exception: {type(read_error).__name__}: {read_error}")
|
||||||
ret, frame = False, None
|
ret, frame = False, None
|
||||||
|
|
||||||
if not ret or frame is None:
|
if not ret or frame is None:
|
||||||
consecutive_errors += 1
|
consecutive_errors += 1
|
||||||
|
|
||||||
# Verbose logging to see actual errors
|
# Enhanced logging to diagnose the issue
|
||||||
logger.error(f"Camera {self.camera_id}: cap.read() failed - ret={ret}, frame={frame is not None}")
|
logger.error(f"Camera {self.camera_id}: cap.read() failed - ret={ret}, frame={frame is not None}")
|
||||||
|
|
||||||
# Try to get more info from the capture
|
# Try to get more info from the capture
|
||||||
try:
|
try:
|
||||||
if self.cap.isOpened():
|
if self.cap and self.cap.isOpened():
|
||||||
backend = self.cap.getBackendName()
|
backend = self.cap.getBackendName()
|
||||||
logger.debug(f"Camera {self.camera_id}: Capture still open, backend: {backend}")
|
pos_frames = self.cap.get(cv2.CAP_PROP_POS_FRAMES)
|
||||||
|
logger.error(f"Camera {self.camera_id}: Capture open, backend: {backend}, pos_frames: {pos_frames}")
|
||||||
else:
|
else:
|
||||||
logger.error(f"Camera {self.camera_id}: Capture is closed!")
|
logger.error(f"Camera {self.camera_id}: Capture is closed or None!")
|
||||||
except Exception as info_error:
|
except Exception as info_error:
|
||||||
logger.error(f"Camera {self.camera_id}: Error getting capture info: {type(info_error).__name__}: {info_error}")
|
logger.error(f"Camera {self.camera_id}: Error getting capture info: {type(info_error).__name__}: {info_error}")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue