Merge pull request #39 from bandi13/fix_memory
Process only 1k frames at a time to minimize memory footprint
This commit is contained in:
16
refacer.py
16
refacer.py
@@ -173,6 +173,12 @@ class Refacer:
|
||||
if audio_stream is not None:
|
||||
self.video_has_audio = True
|
||||
|
||||
def reface_group(self, faces, frames, output):
|
||||
with ThreadPoolExecutor(max_workers = self.use_num_cpus) as executor:
|
||||
results = list(tqdm(executor.map(self.process_faces, frames), total=len(frames),desc="Processing frames"))
|
||||
for result in results:
|
||||
output.write(result)
|
||||
|
||||
def reface(self, video_path, faces):
|
||||
self.__check_video_has_audio(video_path)
|
||||
output_video_path = os.path.join('out',Path(video_path).name)
|
||||
@@ -199,13 +205,15 @@ class Refacer:
|
||||
pbar.update()
|
||||
else:
|
||||
break
|
||||
if (len(frames) > 1000):
|
||||
self.reface_group(faces,frames,output)
|
||||
frames=[]
|
||||
|
||||
cap.release()
|
||||
pbar.close()
|
||||
|
||||
with ThreadPoolExecutor(max_workers = self.use_num_cpus) as executor:
|
||||
results = list(tqdm(executor.map(self.process_faces, frames), total=len(frames),desc="Processing frames"))
|
||||
for result in results:
|
||||
output.write(result)
|
||||
self.reface_group(faces,frames,output)
|
||||
frames=[]
|
||||
output.release()
|
||||
|
||||
return self.__convert_video(video_path,output_video_path)
|
||||
|
||||
Reference in New Issue
Block a user