From 6f59a0826cad89eda422bc6f9c606f802d80f86e Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Tue, 12 Apr 2022 18:40:42 -0400 Subject: [PATCH] [+] Tool for combining videos --- powershell.ps1 | 5 +++++ scripts/helpers/video.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/powershell.ps1 b/powershell.ps1 index 25b59c2..1435301 100644 --- a/powershell.ps1 +++ b/powershell.ps1 @@ -21,6 +21,11 @@ set-alias pip3.9 C:\"Program Files"\Python39\Scripts\pip3.exe set-alias python3.10 C:\Python310\python.exe set-alias python3.10 C:\Python310\Scripts\pip3.exe +# Video tools +function vcompy() { + ipython -i $HOME\zshrc\scripts\helpers\video.py +} + # Minecraft coloring function color($tmp) { $033 = [char]27 diff --git a/scripts/helpers/video.py b/scripts/helpers/video.py index 9f167db..fa79870 100755 --- a/scripts/helpers/video.py +++ b/scripts/helpers/video.py @@ -1,7 +1,11 @@ #!/usr/bin/env python3 +from __future__ import annotations + import os +import re import sys from datetime import datetime +from pathlib import Path def comp(input: str = 'latest', proc: str = 'cpu', codec: str = 'x264', crf: int = 24, br: int = 500, @@ -45,6 +49,39 @@ def comp(input: str = 'latest', proc: str = 'cpu', codec: str = 'x264', crf: int os.system(c) +def combine(format: str, output: str | Path): + """ + Combine videos + + :param format: Regex pattern + :param output: Output file name + """ + pattern = re.compile(format) + + # Find video files + print() + files = [f for f in os.listdir('.') if pattern.match(f)] + print(f'Combining these files: {files}') + + if len(files) == 0: + return print('No files to combine') + + # Write files to text + txt = Path('./temp.txt') + txt.write_text('\n'.join(f"file '{f}'" for f in files)) + + # Infer extension + if '.' not in output: + output = str(Path(output).with_suffix(Path(files[0]).suffix)) + + # Run FFmpeg + print('Running FFmpeg') + os.system(f'ffmpeg -f concat -safe 0 -i temp.txt -c copy {output}') + + # Remove temprary file + os.remove(txt) + + def rename(): for file in os.listdir('.'): if file.startswith('Screen Recording ') or file.startswith('Screen Shot '):