-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert-h265.py
More file actions
53 lines (37 loc) · 1.15 KB
/
convert-h265.py
File metadata and controls
53 lines (37 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import shutil
import subprocess
from os import path
files = []
errors = []
def file_exist(location: str):
ext = path.splitext(location)[1]
if ext == ".mp4" or ext == ".avi" or ext == ".webm" or ext == ".gif":
files.append(location)
def convert_file(file_name: str, folder_name: str):
try:
create_folder(folder_name)
convert_h265(file_name)
os.chdir(move_path)
except Exception as _:
errors.append(file_name)
os.chdir(move_path)
print("Error", file_name)
def create_folder(file_name: str):
dir_name = path.join(path.abspath('')) + '\\' + file_name
if not os.path.exists(dir_name):
os.mkdir(dir_name)
os.chdir(dir_name)
def convert_h265(file_name: str):
subprocess.run(
f"ffmpeg -i \"{move_path}\\{file_name}\" -c:v libx265 -crf 28 -preset faster -c:a aac -b:a 128k \"{move_path}\\out\\{file_name}\"")
def main():
move_path = path.abspath('.')
tmp_files = os.listdir(move_path)
for my_file in tmp_files:
file_exist(my_file)
return move_path
move_path = main()
print(len(files))
for nfile in files:
convert_file(nfile, 'out')