From 1949b8f73f572b52b321aab3d47b3f8a3b040fbb Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Tue, 31 May 2022 21:52:19 +0200 Subject: [PATCH] initial commit --- convert.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 convert.py diff --git a/convert.py b/convert.py new file mode 100755 index 0000000..c397515 --- /dev/null +++ b/convert.py @@ -0,0 +1,39 @@ +#! /usr/bin/python + +import subprocess, argparse + +def main(): + parser = argparse.ArgumentParser(description='Call ffmpeg for converting small video files to mp4 or webp') + parser.add_argument('input', help='input file or url') + parser.add_argument('output', help='output filename') + parser.add_argument('-s', '--start', help='start time, if not 00:00') + parser.add_argument('-t', '--to', help='end time, if not end of file') + parser.add_argument('-q', '--quality', help='quality of output, as a percentage') + args = parser.parse_args() + f_args = [] + + if "https" in args.input: + # get direct urls from youtube-dl + urls = subprocess.run(["youtube-dl", "--get-url", args.input], capture_output=True, encoding='utf-8') + for url in urls.stdout.split('\n'): + if len(url) > 10: + f_args += ["-i", url] + else: + # local file, or single local http stream + f_args += ["-i", args.input] + + if args.start: + f_args += ["-ss", args.start] + if args.to: + f_args += ["-to", args.to] + + if ".webp" in args.output: + f_args += ["-vcodec", "libwebp"] + f_args += ["-preset", "default"] + f_args += ["-loop", "0", "-an", "-vsync", "0"] + f_args += ["-qscale", args.quality if args.quality else "70"] + + subprocess.run(["ffmpeg", "-y"] + f_args + [args.output if args.output else "output.mp4"]) + +if __name__ == "__main__": + main()