From 8bb898fe5d5b1bab286e83a462f1fb9e258b8254 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Wed, 27 Dec 2023 14:12:05 +0100 Subject: [PATCH] unsymlink vc script --- .scripts/vc | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) mode change 120000 => 100755 .scripts/vc diff --git a/.scripts/vc b/.scripts/vc deleted file mode 120000 index 1a9c0c3..0000000 --- a/.scripts/vc +++ /dev/null @@ -1 +0,0 @@ -/home/mark/workspace/repos/ffmpegwrap/convert.py \ No newline at end of file diff --git a/.scripts/vc b/.scripts/vc new file mode 100755 index 0000000..4055b9e --- /dev/null +++ b/.scripts/vc @@ -0,0 +1,59 @@ +#! /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') + parser.add_argument('-S', '--silent', action='store_true', help='no audio') + parser.add_argument('-c', '--crop', help='Crop') + args = parser.parse_args() + f_args = [] + + if "https" in args.input: + # get direct urls from youtube-dl + urls = subprocess.run(["yt-dlp", "--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] + + vfilter = "scale=-2:'min(720,ih)'" + if args.crop: + vfilter += f",crop={args.crop}" + f_args += ["-vf", vfilter] + + if args.start: + f_args += ["-ss", args.start] + if args.to: + f_args += ["-to", args.to] + if args.silent: + f_args += ["-an"] + f_args += ["-sn"] + f_args += ["-dn"] + f_args += ["-map_metadata:c", "-1"] + + 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"] + else: + f_args += ["-c:v", "libx264"] + f_args += ["-preset", "veryfast"] + f_args += ["-crf", "26"] + f_args += ["-c:a", "aac"] + f_args += ["-b:a", "128k"] + f_args += ["-pix_fmt", "yuv420p"] + print(f_args) + + subprocess.run(["ffmpeg", "-y"] + f_args + [args.output if args.output else "output.mp4"]) + +if __name__ == "__main__": + main()