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:
|
if audio_stream is not None:
|
||||||
self.video_has_audio = True
|
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):
|
def reface(self, video_path, faces):
|
||||||
self.__check_video_has_audio(video_path)
|
self.__check_video_has_audio(video_path)
|
||||||
output_video_path = os.path.join('out',Path(video_path).name)
|
output_video_path = os.path.join('out',Path(video_path).name)
|
||||||
@@ -199,13 +205,15 @@ class Refacer:
|
|||||||
pbar.update()
|
pbar.update()
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
if (len(frames) > 1000):
|
||||||
|
self.reface_group(faces,frames,output)
|
||||||
|
frames=[]
|
||||||
|
|
||||||
cap.release()
|
cap.release()
|
||||||
pbar.close()
|
pbar.close()
|
||||||
|
|
||||||
with ThreadPoolExecutor(max_workers = self.use_num_cpus) as executor:
|
self.reface_group(faces,frames,output)
|
||||||
results = list(tqdm(executor.map(self.process_faces, frames), total=len(frames),desc="Processing frames"))
|
frames=[]
|
||||||
for result in results:
|
|
||||||
output.write(result)
|
|
||||||
output.release()
|
output.release()
|
||||||
|
|
||||||
return self.__convert_video(video_path,output_video_path)
|
return self.__convert_video(video_path,output_video_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user