Merge pull request #338 from phineas-pta/next

ffmpeg platform-agnostic hardware-acceleration
This commit is contained in:
Henry Ruhs 2023-06-05 12:39:05 +02:00 committed by GitHub
commit 3747fc2301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View File

@ -209,6 +209,8 @@ def start(preview_callback = None):
process_video_multi_cores(args.source_img, args.frame_paths)
else:
process_video(args.source_img, args.frame_paths)
if args.gpu_vendor == 'nvidia':
torch.cuda.empty_cache() # prevent CUDA OOM when using ffmpeg cuda accel
status("creating video...")
create_video(video_name, exact_fps, output_dir)
status("adding audio...")

View File

@ -31,8 +31,7 @@ def detect_fps(input_path):
def run_ffmpeg(args):
log_level = f'-loglevel {roop.globals.log_level}'
run_command(f'ffmpeg {log_level} {args}')
run_command(f'ffmpeg -hide_banner -hwaccel auto -loglevel {roop.globals.log_level} {args}')
def set_fps(input_path, output_path, fps):
@ -41,15 +40,13 @@ def set_fps(input_path, output_path, fps):
def create_video(video_name, fps, output_dir):
hwaccel_option = '-hwaccel cuda' if roop.globals.gpu_vendor == 'nvidia' else ''
output_dir = path(output_dir)
run_ffmpeg(f'{hwaccel_option} -framerate "{fps}" -i "{output_dir}{sep}%04d.png" -c:v libx264 -crf 7 -pix_fmt yuv420p -y "{output_dir}{sep}output.mp4"')
run_ffmpeg(f'-framerate "{fps}" -i "{output_dir}{sep}%04d.png" -c:v libx264 -crf 7 -pix_fmt yuv420p -y "{output_dir}{sep}output.mp4"')
def extract_frames(input_path, output_dir):
hwaccel_option = '-hwaccel cuda' if roop.globals.gpu_vendor == 'nvidia' else ''
input_path, output_dir = path(input_path), path(output_dir)
run_ffmpeg(f' {hwaccel_option} -i "{input_path}" "{output_dir}{sep}%04d.png"')
run_ffmpeg(f'-i "{input_path}" "{output_dir}{sep}%04d.png"')
def add_audio(output_dir, target_path, video, keep_frames, output_file):