refactor: change temporary file format from JPG to PPM for improved frame reading
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 2m52s
Build Worker Base and Application Images / deploy-stack (push) Successful in 13s
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 2m52s
Build Worker Base and Application Images / deploy-stack (push) Successful in 13s
This commit is contained in:
parent
73c3367681
commit
fe0da18d0f
1 changed files with 21 additions and 32 deletions
|
@ -94,8 +94,8 @@ class FFmpegRTSPReader:
|
||||||
self.temp_file = f"/tmp/claude/camera_{self.camera_id.replace(' ', '_')}.raw"
|
self.temp_file = f"/tmp/claude/camera_{self.camera_id.replace(' ', '_')}.raw"
|
||||||
os.makedirs("/tmp/claude", exist_ok=True)
|
os.makedirs("/tmp/claude", exist_ok=True)
|
||||||
|
|
||||||
# Change to JPG format which properly supports -update 1
|
# Use PPM format - uncompressed with header, supports -update 1
|
||||||
self.temp_file = f"/tmp/claude/camera_{self.camera_id.replace(' ', '_')}.jpg"
|
self.temp_file = f"/tmp/claude/camera_{self.camera_id.replace(' ', '_')}.ppm"
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
'ffmpeg',
|
'ffmpeg',
|
||||||
|
@ -104,8 +104,8 @@ class FFmpegRTSPReader:
|
||||||
'-rtsp_transport', 'tcp',
|
'-rtsp_transport', 'tcp',
|
||||||
'-i', self.rtsp_url,
|
'-i', self.rtsp_url,
|
||||||
'-f', 'image2',
|
'-f', 'image2',
|
||||||
'-update', '1', # This actually works with image2 format
|
'-update', '1', # Works with image2 format
|
||||||
'-q:v', '2', # High quality JPEG
|
'-pix_fmt', 'rgb24', # PPM uses RGB not BGR
|
||||||
'-an', # No audio
|
'-an', # No audio
|
||||||
'-y', # Overwrite output file
|
'-y', # Overwrite output file
|
||||||
self.temp_file
|
self.temp_file
|
||||||
|
@ -176,39 +176,28 @@ class FFmpegRTSPReader:
|
||||||
if self.frame_ready_event.wait(timeout=restart_check_interval):
|
if self.frame_ready_event.wait(timeout=restart_check_interval):
|
||||||
self.frame_ready_event.clear()
|
self.frame_ready_event.clear()
|
||||||
|
|
||||||
# Read JPEG frame with concurrency safety
|
# Read PPM frame (uncompressed with header)
|
||||||
try:
|
try:
|
||||||
# Try to read JPEG multiple times to handle race conditions
|
if os.path.exists(self.temp_file):
|
||||||
frame = None
|
# Read PPM with OpenCV (handles RGB->BGR conversion automatically)
|
||||||
for attempt in range(3):
|
frame = cv2.imread(self.temp_file)
|
||||||
try:
|
|
||||||
# Read and decode JPEG directly
|
|
||||||
frame = cv2.imread(self.temp_file)
|
|
||||||
|
|
||||||
if frame is not None and frame.shape == (self.height, self.width, 3):
|
if frame is not None and frame.shape == (self.height, self.width, 3):
|
||||||
break
|
# Call frame callback directly
|
||||||
else:
|
if self.frame_callback:
|
||||||
logger.debug(f"Camera {self.camera_id}: Invalid frame shape or None, attempt {attempt+1}")
|
self.frame_callback(self.camera_id, frame)
|
||||||
time.sleep(0.01) # Brief wait before retry
|
|
||||||
|
|
||||||
except (IOError, OSError) as e:
|
frame_count += 1
|
||||||
logger.debug(f"Camera {self.camera_id}: Read error on attempt {attempt+1}: {e}")
|
|
||||||
time.sleep(0.01)
|
|
||||||
|
|
||||||
if frame is not None:
|
# Log progress
|
||||||
# Call frame callback directly
|
current_time = time.time()
|
||||||
if self.frame_callback:
|
if current_time - last_log_time >= 30:
|
||||||
self.frame_callback(self.camera_id, frame)
|
logger.info(f"Camera {self.camera_id}: {frame_count} PPM frames processed reactively")
|
||||||
|
last_log_time = current_time
|
||||||
frame_count += 1
|
else:
|
||||||
|
logger.debug(f"Camera {self.camera_id}: Invalid PPM frame")
|
||||||
# Log progress
|
|
||||||
current_time = time.time()
|
|
||||||
if current_time - last_log_time >= 30:
|
|
||||||
logger.info(f"Camera {self.camera_id}: {frame_count} JPEG frames processed reactively")
|
|
||||||
last_log_time = current_time
|
|
||||||
else:
|
else:
|
||||||
logger.debug(f"Camera {self.camera_id}: Failed to read valid JPEG after retries")
|
logger.debug(f"Camera {self.camera_id}: PPM file not found yet")
|
||||||
|
|
||||||
except (IOError, OSError) as e:
|
except (IOError, OSError) as e:
|
||||||
logger.debug(f"Camera {self.camera_id}: File read error: {e}")
|
logger.debug(f"Camera {self.camera_id}: File read error: {e}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue