add thread to write frames to disk

This commit is contained in:
Blake Blackshear 2020-01-06 20:36:38 -06:00
parent 49dc029c43
commit 65579e9cbf
2 changed files with 21 additions and 3 deletions

View File

@ -246,9 +246,7 @@ class ObjectTracker(threading.Thread):
while True: while True:
frame_time = self.camera.refined_frame_queue.get() frame_time = self.camera.refined_frame_queue.get()
self.match_and_update(self.camera.detected_objects[frame_time]) self.match_and_update(self.camera.detected_objects[frame_time])
# f = open(f"/debug/{str(frame_time)}.jpg", 'wb') self.camera.frame_tracked_queue.put(frame_time)
# f.write(self.camera.frame_with_objects(frame_time))
# f.close()
def register(self, index, obj): def register(self, index, obj):
id = f"{str(obj['frame_time'])}-{index}" id = f"{str(obj['frame_time'])}-{index}"

View File

@ -107,6 +107,21 @@ class CameraCapture(threading.Thread):
self.camera.fps.update() self.camera.fps.update()
class VideoWriter(threading.Thread):
def __init__(self, camera):
threading.Thread.__init__(self)
self.camera = camera
def run(self):
prctl.set_name("VideoWriter")
while True:
frame_time = self.camera.frame_tracked_queue.get()
if len(self.camera.detected_objects[frame_time]) == 0:
continue
f = open(f"/debug/{self.camera.name}-{str(frame_time)}.jpg", 'wb')
f.write(self.camera.frame_with_objects(frame_time))
f.close()
class Camera: class Camera:
def __init__(self, name, ffmpeg_config, global_objects_config, config, prepped_frame_queue, mqtt_client, mqtt_prefix): def __init__(self, name, ffmpeg_config, global_objects_config, config, prepped_frame_queue, mqtt_client, mqtt_prefix):
self.name = name self.name = name
@ -122,6 +137,7 @@ class Camera:
self.regions_in_process_lock = mp.Lock() self.regions_in_process_lock = mp.Lock()
self.finished_frame_queue = queue.Queue() self.finished_frame_queue = queue.Queue()
self.refined_frame_queue = queue.Queue() self.refined_frame_queue = queue.Queue()
self.frame_tracked_queue = queue.Queue()
self.ffmpeg = config.get('ffmpeg', {}) self.ffmpeg = config.get('ffmpeg', {})
self.ffmpeg_input = get_ffmpeg_input(self.ffmpeg['input']) self.ffmpeg_input = get_ffmpeg_input(self.ffmpeg['input'])
@ -206,6 +222,10 @@ class Camera:
self.object_tracker = ObjectTracker(self, 10) self.object_tracker = ObjectTracker(self, 10)
self.object_tracker.start() self.object_tracker.start()
# start a thread to write tracked frames to disk
self.video_writer = VideoWriter(self)
self.video_writer.start()
# start a thread to publish object scores # start a thread to publish object scores
mqtt_publisher = MqttObjectPublisher(self.mqtt_client, self.mqtt_topic_prefix, self.objects_parsed, self.detected_objects, self.best_frames) mqtt_publisher = MqttObjectPublisher(self.mqtt_client, self.mqtt_topic_prefix, self.objects_parsed, self.detected_objects, self.best_frames)
mqtt_publisher.start() mqtt_publisher.start()