[+] Video compression tools

This commit is contained in:
Hykilpikonna
2021-12-07 19:04:09 -05:00
parent 0e9f16a44b
commit 892d8a7b1c
3 changed files with 38 additions and 0 deletions
View File
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
import os
import sys
from datetime import datetime
if __name__ == '__main__':
args = sys.argv[1:]
if len(args) < 2:
print('Usage: compress [rename/cpu/gpu] <input> [crf=20]')
# Command to rename all screen recordings
if args[0] == 'rename':
for file in os.listdir('.'):
if file.startswith('Screen Recording ') or file.startswith('Screen Shot '):
pre = 'Rec' if 'Recording' in file else 'Shot'
endIndex = (file.index('AM') if 'AM' in file else file.index('PM')) + 2
datestr = file[17 if pre == 'Rec' else 12:endIndex]
dt = datetime.strptime(datestr, '%Y-%m-%d at %I.%M.%S %p')
date = dt.strftime(f'{pre} %Y-%m-%d %H-%M' + file[endIndex:])
print(f'Renaming {file} to {date}')
os.rename(file, date)
exit()
processor = args[0].lower().strip()
i = args[1]
crf = args[2] if len(args) > 2 else '24'
out = i[:i.rindex('.')] + f'.{processor[0]}265'
if processor == 'cpu':
out += f'-{crf}'
out += '.mp4'
if processor == 'cpu':
os.system(f'ffmpeg -i "{i}" -vcodec libx265 -crf {crf} "{out}"')
if processor == 'gpu':
os.system(f'ffmpeg -i "{i}" -c:v hevc_videotoolbox -b:v 4000k "{out}"')
+1
View File
@@ -118,6 +118,7 @@ cut() {
echo $start
ffmpeg -i $1 -codec copy -ss $start -t $2 Cut\ $1
}
alias vcomp="$SCR/helpers/video.py"
# include if it exists
[ -f $HOME/extra.rc.sh ] && . $HOME/extra.rc.sh