Files
facefusion/facefusion/video_manager.py
T
Henry Ruhs 3f81a8a784 patch-3.7.1 (#1178)
* patch 3.7.1

* fix bug for 2 processors on image to image pipeline (#1177)

* reduce default value of target_frame_amount

* restore old performance

* restore old performance

* restore old performance

* restore old performance
2026-07-05 16:43:36 +02:00

47 lines
1.2 KiB
Python

import cv2
from facefusion.types import VideoPoolSet
VIDEO_POOL_SET : VideoPoolSet =\
{
'capture': {},
'writer': {}
}
def get_video_capture(video_path : str) -> cv2.VideoCapture:
if video_path not in VIDEO_POOL_SET.get('capture'):
video_capture = cv2.VideoCapture(video_path)
if video_capture.isOpened():
VIDEO_POOL_SET['capture'][video_path] = video_capture
return VIDEO_POOL_SET.get('capture').get(video_path)
def conditional_set_video_frame_position(video_capture : cv2.VideoCapture, frame_position : int) -> bool:
if not video_capture.get(cv2.CAP_PROP_POS_FRAMES) == frame_position:
return video_capture.set(cv2.CAP_PROP_POS_FRAMES, frame_position)
return True
def get_video_writer(video_path : str) -> cv2.VideoWriter:
if video_path not in VIDEO_POOL_SET.get('writer'):
video_writer = cv2.VideoWriter()
if video_writer.isOpened():
VIDEO_POOL_SET['writer'][video_path] = video_writer
return VIDEO_POOL_SET.get('writer').get(video_path)
def clear_video_pool() -> None:
for video_capture in VIDEO_POOL_SET.get('capture').values():
video_capture.release()
for video_writer in VIDEO_POOL_SET.get('writer').values():
video_writer.release()
VIDEO_POOL_SET['capture'].clear()
VIDEO_POOL_SET['writer'].clear()