refactor: update FFmpegRTSPReader to read and update a single frame in place for improved efficiency
Some checks failed
Build Worker Base and Application Images / check-base-changes (push) Successful in 10s
Build Worker Base and Application Images / build-base (push) Has been skipped
Build Worker Base and Application Images / build-docker (push) Successful in 3m0s
Build Worker Base and Application Images / deploy-stack (push) Has been cancelled
Some checks failed
Build Worker Base and Application Images / check-base-changes (push) Successful in 10s
Build Worker Base and Application Images / build-base (push) Has been skipped
Build Worker Base and Application Images / build-docker (push) Successful in 3m0s
Build Worker Base and Application Images / deploy-stack (push) Has been cancelled
This commit is contained in:
parent
cb31633cc1
commit
84144a2955
1 changed files with 2 additions and 11 deletions
|
@ -100,6 +100,7 @@ class FFmpegRTSPReader:
|
|||
'-f', 'rawvideo',
|
||||
'-pix_fmt', 'bgr24',
|
||||
'-an', # No audio
|
||||
'-update', '1', # Update single frame in place
|
||||
'-y', # Overwrite output file
|
||||
self.temp_file
|
||||
]
|
||||
|
@ -169,19 +170,9 @@ class FFmpegRTSPReader:
|
|||
if self.frame_ready_event.wait(timeout=restart_check_interval):
|
||||
self.frame_ready_event.clear()
|
||||
|
||||
# Read latest frame
|
||||
# Read current frame (file is always exactly one frame)
|
||||
try:
|
||||
with open(self.temp_file, 'rb') as f:
|
||||
# Get file size
|
||||
f.seek(0, 2)
|
||||
file_size = f.tell()
|
||||
|
||||
if file_size < bytes_per_frame:
|
||||
continue
|
||||
|
||||
# Read last complete frame
|
||||
last_frame_offset = (file_size // bytes_per_frame - 1) * bytes_per_frame
|
||||
f.seek(last_frame_offset)
|
||||
frame_data = f.read(bytes_per_frame)
|
||||
|
||||
if len(frame_data) == bytes_per_frame:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue