From 60128d3e96efd307dadd56a838a4a57283fc6fc1 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 7 Jun 2023 20:01:42 +0200 Subject: [PATCH] Add video encoder via CLI --- README.md | 19 ++++++++++++------- roop/core.py | 4 +++- roop/globals.py | 1 + roop/utilities.py | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9d19aa9..7de722c 100644 --- a/README.md +++ b/README.md @@ -34,23 +34,28 @@ Additional command line arguments are given below: ``` options: -h, --help show this help message and exit - -f SOURCE_IMG, --face SOURCE_IMG - use this face + -f SOURCE_PATH, --face SOURCE_PATH + use a face image -t TARGET_PATH, --target TARGET_PATH - replace this face - -o OUTPUT_FILE, --output OUTPUT_FILE + replace image or video with face + -o OUTPUT_PATH, --output OUTPUT_PATH save output to this file --keep-fps maintain original fps + --keep-audio maintain original audio --keep-frames keep frames directory - --all-faces swap all faces in frame + --many-faces swap every face in the frame + --video-encoder VIDEO_ENCODER + adjust output video encoder + --video-quality VIDEO_QUALITY + adjust output video quality --max-memory MAX_MEMORY maximum amount of RAM in GB to be used --cpu-cores CPU_CORES number of CPU cores to use --gpu-threads GPU_THREADS number of threads to be use for the GPU - --gpu-vendor {apple,amd,intel,nvidia} - choice your GPU vendor + --gpu-vendor {apple,amd,nvidia} + select your GPU vendor ``` Looking for a CLI mode? Using the -f/--face argument will make the program in cli mode. diff --git a/roop/core.py b/roop/core.py index ab8dd07..906151f 100755 --- a/roop/core.py +++ b/roop/core.py @@ -42,7 +42,8 @@ def parse_args() -> None: parser.add_argument('--keep-audio', help='maintain original audio', dest='keep_audio', action='store_true', default=True) parser.add_argument('--keep-frames', help='keep frames directory', dest='keep_frames', action='store_true', default=False) parser.add_argument('--many-faces', help='swap every face in the frame', dest='many_faces', action='store_true', default=False) - parser.add_argument('--video-quality', help='adjust video quality of output file', dest='video_quality', type=int, default=10) + parser.add_argument('--video-encoder', help='adjust output video encoder', dest='video_encoder', default='libx264') + parser.add_argument('--video-quality', help='adjust output video quality', dest='video_quality', type=int, default=10) parser.add_argument('--max-memory', help='maximum amount of RAM in GB to be used', dest='max_memory', type=int) parser.add_argument('--cpu-cores', help='number of CPU cores to use', dest='cpu_cores', type=int, default=max(psutil.cpu_count() / 2, 1)) parser.add_argument('--gpu-threads', help='number of threads to be use for the GPU', dest='gpu_threads', type=int, default=8) @@ -58,6 +59,7 @@ def parse_args() -> None: roop.globals.keep_audio = args.keep_audio roop.globals.keep_frames = args.keep_frames roop.globals.many_faces = args.many_faces + roop.globals.video_encoder = args.video_encoder roop.globals.video_quality = args.video_quality if args.cpu_cores: diff --git a/roop/globals.py b/roop/globals.py index f280566..4ad9085 100644 --- a/roop/globals.py +++ b/roop/globals.py @@ -7,6 +7,7 @@ keep_fps = None keep_audio = None keep_frames = None many_faces = None +video_encoder = None video_quality = None cpu_cores = None gpu_threads = None diff --git a/roop/utilities.py b/roop/utilities.py index 8746a75..da4dd84 100644 --- a/roop/utilities.py +++ b/roop/utilities.py @@ -35,7 +35,7 @@ def extract_frames(target_path: str) -> None: def create_video(target_path: str, fps: int) -> None: - run_ffmpeg(['-i', get_temp_directory_path(target_path) + os.sep + '%04d.png', '-framerate', str(fps), '-c:v', 'libx264', '-crf', str(roop.globals.video_quality), '-pix_fmt', 'yuv420p', '-y', get_temp_file_path(target_path)]) + run_ffmpeg(['-i', get_temp_directory_path(target_path) + os.sep + '%04d.png', '-framerate', str(fps), '-c:v', roop.globals.video_encoder, '-crf', str(roop.globals.video_quality), '-pix_fmt', 'yuv420p', '-y', get_temp_file_path(target_path)]) def restore_audio(target_path: str, output_path: str) -> None: