Better input handling

This commit is contained in:
Amber McCloughan 2024-07-25 23:21:55 -04:00
parent 8edf92e0cc
commit f99c31f704
1 changed files with 7 additions and 7 deletions

View File

@ -45,10 +45,10 @@ def get_tag() -> str:
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=5)) return ''.join(random.choices(string.ascii_uppercase + string.digits, k=5))
def call_ffmpeg(command: str) -> bool: def call_ffmpeg(command: List[str]) -> bool:
print("ffmpeg", *command.split(' ')) print("ffmpeg", ' '.join(command))
process = subprocess.run(["ffmpeg", '-hide_banner', '-loglevel', 'error', full_command = ["ffmpeg", '-hide_banner', '-loglevel', 'error'] + command
*command.split(' ')]) process = subprocess.run(full_command)
return process.returncode == 0 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: for input in inputs:
file_name = f"{Path(input).stem}_{tag}.gif" file_name = f"{Path(input).stem}_{tag}.gif"
full_path = f"{Path(input).parent}/{file_name}" full_path = f"{Path(input).parent}/{file_name}"
success = call_ffmpeg(f"-i {input} -f gif -r {framerate} -filter_complex {interpolate_cmd}scale={ \ 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 { \ width}:-1:flags={scaler},split[v1][v2];[v1]palettegen[plt];[v2][plt]paletteuse", f"{full_path}"]
full_path}") success = call_ffmpeg(command)
# Tuple of (was it successful?, path of output) # Tuple of (was it successful?, path of output)
output_map[input] = (success, full_path) output_map[input] = (success, full_path)