-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use multiprocessing for writing Flir frames #465
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes in the stop process to clear the process and to avoid dangling reference just in case.
def stop(self): if self.open and self.recording: self.logger.debug('FLIR: Setting Record Stop Flag') self.recording = False if self.save_process is not None: #wait for child process to finish self.save_process.join(timeout=5) if self.save_process.is_alive(): self.logger.error('FLIR: Save process did not terminate in time.') #terminating the child process self.save_process.terminate() #clear the save_process reference just in case self.save_process = None self.streaming = False
neurobooth_os/iout/flir_cam.py
Outdated
self.save_thread.start() | ||
|
||
try: | ||
self.save_process = multiprocessing.Process(target = self.camCaptureVid()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change here -> passing the function object instead of calling the function.
self.save_process = multiprocessing.Process(target = self.camCaptureVid)
neurobooth_os/iout/flir_cam.py
Outdated
@@ -151,7 +150,7 @@ def createOutlet(self): | |||
# function to capture images, convert to numpy, send to queue, and release | |||
# from buffer in separate process | |||
def camCaptureVid(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can create a video writer here (that gets created in the child process instead). this can be the rewritten function:
#rewritten function
def camCaptureVid(self):
try:
# Initializing VideoWriter in the child process instead
fourcc = cv2.VideoWriter_fourcc(*"MJPG")
video_out = cv2.VideoWriter(
self.video_filename, fourcc,
self.FRAME_RATE_OUT, self.frameSize
)
self.logger.debug('FLIR: Save Process Started')
#write the frames from the queue as before
while self.recording or not self.image_queue.empty():
try:
# Retrieve frame from the queue
dequeuedImage = self.image_queue.get(block=True, timeout=1)
# Write frame to the video file
video_out.write(dequeuedImage)
except queue.Empty:
continue
except Exception as e:
self.logger.error(f'FLIR: Error in save process: {e}')
finally:
# Safely release video writer
video_out.release()
self.logger.debug('FLIR: Exiting Save Process')
This will be removed
Short PR that swaps multi-threading for multiprocesing to see if there's any improvement in write performance.
This change should be considered temporary, as it's not clear that this is an appropriate approach for image processing.