refactor: improve error handling and logging in RTSPReader for frame capture failures
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 2m55s
Build Worker Base and Application Images / deploy-stack (push) Successful in 23s
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 2m55s
Build Worker Base and Application Images / deploy-stack (push) Successful in 23s
This commit is contained in:
parent
c6a4258055
commit
a1e7c42fb3
1 changed files with 13 additions and 5 deletions
|
@ -89,7 +89,11 @@ class RTSPReader:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Read frame immediately without rate limiting for minimum latency
|
# Read frame immediately without rate limiting for minimum latency
|
||||||
ret, frame = self.cap.read()
|
try:
|
||||||
|
ret, frame = self.cap.read()
|
||||||
|
except Exception as read_error:
|
||||||
|
logger.error(f"Camera {self.camera_id}: cap.read() threw exception: {type(read_error).__name__}: {read_error}")
|
||||||
|
ret, frame = False, None
|
||||||
|
|
||||||
if not ret or frame is None:
|
if not ret or frame is None:
|
||||||
consecutive_errors += 1
|
consecutive_errors += 1
|
||||||
|
@ -98,10 +102,14 @@ class RTSPReader:
|
||||||
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
|
||||||
if self.cap.isOpened():
|
try:
|
||||||
logger.debug(f"Camera {self.camera_id}: Capture still open, backend: {self.cap.getBackendName()}")
|
if self.cap.isOpened():
|
||||||
else:
|
backend = self.cap.getBackendName()
|
||||||
logger.error(f"Camera {self.camera_id}: Capture is closed!")
|
logger.debug(f"Camera {self.camera_id}: Capture still open, backend: {backend}")
|
||||||
|
else:
|
||||||
|
logger.error(f"Camera {self.camera_id}: Capture is closed!")
|
||||||
|
except Exception as info_error:
|
||||||
|
logger.error(f"Camera {self.camera_id}: Error getting capture info: {type(info_error).__name__}: {info_error}")
|
||||||
|
|
||||||
if consecutive_errors >= self.max_consecutive_errors:
|
if consecutive_errors >= self.max_consecutive_errors:
|
||||||
logger.error(f"Camera {self.camera_id}: Too many consecutive errors ({consecutive_errors}), reinitializing")
|
logger.error(f"Camera {self.camera_id}: Too many consecutive errors ({consecutive_errors}), reinitializing")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue