[+] Tool for combining videos
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 '):
|
||||
|
||||
Reference in New Issue
Block a user