From f99c31f704262933dec35d1735dfb7df0ce1bcac Mon Sep 17 00:00:00 2001 From: Amber Date: Thu, 25 Jul 2024 23:21:55 -0400 Subject: [PATCH] Better input handling --- video_to_gif.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/video_to_gif.py b/video_to_gif.py index b65d468..4603dcc 100644 --- a/video_to_gif.py +++ b/video_to_gif.py @@ -45,10 +45,10 @@ def get_tag() -> str: return ''.join(random.choices(string.ascii_uppercase + string.digits, k=5)) -def call_ffmpeg(command: str) -> bool: - print("ffmpeg", *command.split(' ')) - process = subprocess.run(["ffmpeg", '-hide_banner', '-loglevel', 'error', - *command.split(' ')]) +def call_ffmpeg(command: List[str]) -> bool: + print("ffmpeg", ' '.join(command)) + full_command = ["ffmpeg", '-hide_banner', '-loglevel', 'error'] + command + process = subprocess.run(full_command) return process.returncode == 0 @@ -68,9 +68,9 @@ def generate_gif_files(inputs: List[str], args: Dict[str, Any]) -> Dict[str, Tup for input in inputs: file_name = f"{Path(input).stem}_{tag}.gif" full_path = f"{Path(input).parent}/{file_name}" - success = call_ffmpeg(f"-i {input} -f gif -r {framerate} -filter_complex {interpolate_cmd}scale={ \ - width}:-1:flags={scaler},split[v1][v2];[v1]palettegen[plt];[v2][plt]paletteuse { \ - full_path}") + command = ['-i', input, '-f', 'gif', '-r', f"{framerate}", '-filter_complex', f"{interpolate_cmd}scale={ \ + width}:-1:flags={scaler},split[v1][v2];[v1]palettegen[plt];[v2][plt]paletteuse", f"{full_path}"] + success = call_ffmpeg(command) # Tuple of (was it successful?, path of output) output_map[input] = (success, full_path)