fix: camera api endpoint
This commit is contained in:
parent
83aaf95f59
commit
519e073f7f
5 changed files with 69 additions and 68 deletions
|
@ -101,14 +101,14 @@ class FFmpegRTSPReader:
|
|||
# This ensures each file is complete when written
|
||||
camera_id_safe = self.camera_id.replace(' ', '_')
|
||||
self.frame_prefix = f"camera_{camera_id_safe}"
|
||||
# Using strftime pattern with microseconds for unique filenames
|
||||
self.frame_pattern = f"{self.frame_dir}/{self.frame_prefix}_%Y%m%d_%H%M%S_%f.ppm"
|
||||
# Using strftime pattern with seconds for unique filenames (avoid %f which may not work)
|
||||
self.frame_pattern = f"{self.frame_dir}/{self.frame_prefix}_%Y%m%d_%H%M%S.ppm"
|
||||
|
||||
cmd = [
|
||||
'ffmpeg',
|
||||
# DO NOT REMOVE
|
||||
'-hwaccel', 'cuda',
|
||||
'-hwaccel_device', '0',
|
||||
# '-hwaccel', 'cuda',
|
||||
# '-hwaccel_device', '0',
|
||||
'-rtsp_transport', 'tcp',
|
||||
'-i', self.rtsp_url,
|
||||
'-f', 'image2',
|
||||
|
@ -201,14 +201,17 @@ class FFmpegRTSPReader:
|
|||
# Sort by filename (which includes timestamp) and get the latest
|
||||
frame_files.sort()
|
||||
latest_frame = frame_files[-1]
|
||||
logger.debug(f"Camera {self.camera_id}: Found {len(frame_files)} frames, processing latest: {latest_frame}")
|
||||
|
||||
# Read the latest frame (it's complete since FFmpeg wrote it atomically)
|
||||
frame = cv2.imread(latest_frame)
|
||||
|
||||
if frame is not None and frame.shape == (self.height, self.width, 3):
|
||||
# Call frame callback directly
|
||||
if frame is not None:
|
||||
logger.debug(f"Camera {self.camera_id}: Successfully read frame {frame.shape} from {latest_frame}")
|
||||
# Accept any frame dimensions initially for debugging
|
||||
if self.frame_callback:
|
||||
self.frame_callback(self.camera_id, frame)
|
||||
logger.debug(f"Camera {self.camera_id}: Called frame callback")
|
||||
|
||||
frame_count += 1
|
||||
|
||||
|
@ -217,6 +220,8 @@ class FFmpegRTSPReader:
|
|||
if current_time - last_log_time >= 30:
|
||||
logger.info(f"Camera {self.camera_id}: {frame_count} frames processed")
|
||||
last_log_time = current_time
|
||||
else:
|
||||
logger.warning(f"Camera {self.camera_id}: Failed to read frame from {latest_frame}")
|
||||
|
||||
# Clean up old frame files to prevent disk filling
|
||||
# Keep only the latest 5 frames
|
||||
|
@ -226,6 +231,8 @@ class FFmpegRTSPReader:
|
|||
os.remove(old_file)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
logger.warning(f"Camera {self.camera_id}: No frame files found in {self.frame_dir} with pattern {self.frame_prefix}*.ppm")
|
||||
|
||||
except Exception as e:
|
||||
logger.debug(f"Camera {self.camera_id}: Error reading frames: {e}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue