Last active
February 18, 2025 14:47
-
-
Save home-gihub/3315972825b4e5f218a1f2a12f346e6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -- resize0r.py -- # | |
# Lets you create resizing webm videos | |
# You must have ffmpg installed | |
# ----------------- # | |
import sys | |
import subprocess | |
import os | |
import glob | |
import math | |
import random | |
def main(argv: list[str]): | |
print("resiz0r. Running with arguments: " + str(argv)) | |
if len(argv) < 3: | |
print('Too little arguments given!') | |
print('USAGE: resize0r.py <Input file path> <Output file path>') | |
return 1 | |
Input: str = argv[1] | |
Output: str = argv[2] | |
if not os.path.isfile(Input): | |
print("Invalid input path!") | |
return 1 | |
if os.path.isfile(Output): | |
print("File at output path already exists!") | |
return 1 | |
os.mkdir("working") | |
print('Step 1/4 split video...') | |
cmd:str='ffmpeg -i ' + Input + ' ./working/s%03d.png' | |
print('Running: '+cmd) | |
subprocess.call(cmd) | |
print('Done.') | |
print('Step 2/3 resize segments...') | |
i:int=1 | |
vids=glob.glob('./working/*') | |
os.mkdir('./working/prseg/') | |
for f in vids: | |
cmd:str='ffmpeg -i ' + f + ' -filter:v scale=' + str(int(abs(random.randrange(1,352))) * 2) + ':' + str(int(abs(random.randrange(1,240))) *2) + ' ./working/prseg/s'+str(i)+'.webm' | |
print("Running: " + cmd) | |
subprocess.call(cmd) | |
i=i+1 | |
print('Done.') | |
print('Step 3/4 concat segments...') | |
files = glob.glob('./working/prseg/*') | |
cat = open("./working/cat.txt", 'w+') | |
i:int=1 | |
for f in files: | |
cat.write('file ./prseg/s' + str(i) + ".webm\n") | |
i=i+1 | |
cat.close() | |
os.mkdir('./working/noaud/') | |
cmd:str='ffmpeg -safe 0 -f concat -i ./working/cat.txt -crf 25 -c:v copy ./working/noaud/' + Output | |
print('Running: '+cmd) | |
subprocess.call(cmd) | |
print('Done.') | |
print('Step 4/4 copy audio...') | |
cmd:str='ffmpeg -i ./working/noaud/' + Output + ' -i ' + Input + ' -c:v copy -c:a libvorbis -map 0:v -map 1:a -map 1:a ' + Output | |
print('Running: '+cmd) | |
subprocess.call(cmd) | |
print('Done.') | |
print("Cleaning up...") | |
for f in glob.glob('./working/*'): | |
os.remove(f) | |
os.rmdir('./working/') | |
print('Done.') | |
if __name__ == '__main__': | |
main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment