Fix frames vs. cpu cores issue

This commit is contained in:
henryruhs 2023-06-02 16:38:14 +02:00
parent 8b50aaf838
commit dd5a321c50

View File

@ -96,19 +96,22 @@ def pre_check():
def start_processing(): def start_processing():
if args['gpu']: frame_paths = args["frame_paths"]
n = len(frame_paths) // (args['cores_count'])
# single thread
if args['gpu'] or n < 2:
process_video(args['source_img'], args["frame_paths"]) process_video(args['source_img'], args["frame_paths"])
return return
frame_paths = args["frame_paths"] # multi thread of frames to cpu cores ratio is 2
n = len(frame_paths)//(args['cores_count']) if n > 2:
processes = [] processes = []
for i in range(0, len(frame_paths), n): for i in range(0, len(frame_paths), n):
p = pool.apply_async(process_video, args=(args['source_img'], frame_paths[i:i+n],)) p = pool.apply_async(process_video, args=(args['source_img'], frame_paths[i:i+n],))
processes.append(p) processes.append(p)
for p in processes: for p in processes:
p.get() p.get()
pool.close() pool.close()
pool.join() pool.join()
def preview_image(image_path): def preview_image(image_path):