Add video encoder via CLI

This commit is contained in:
henryruhs 2023-06-07 20:01:42 +02:00
parent e37fa75522
commit 60128d3e96
4 changed files with 17 additions and 9 deletions

View File

@ -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.

View File

@ -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:

View File

@ -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

View File

@ -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: