-
Notifications
You must be signed in to change notification settings - Fork 8
/
encode.py
executable file
·111 lines (102 loc) · 3.15 KB
/
encode.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import subprocess, os, glob
from simple_term_menu import TerminalMenu
from utils import is_tool, clear
def encode_to_hevc(fn, out, opts=None):
param_line = "crf=18.0:limit-sao=1:bframes=8:aq-mode=3:psy-rd=1.0"
if opts == None:
detail_menu = TerminalMenu([
"(Recommended if you dont know) One Setting to rule them all",
"(e.g Your Name) Flat, slow anime (slice of life, everything is well lit)",
"(e.g Kimetsu no Yaiba) Some dark scene, some battle scene (shonen, historical, etc.)",
"(Rarely used) [TV Series] Movie-tier dark scene, complex grain/detail",
"(Rarely used) [Movie] Movie-tier dark scene, complex grain/detail",
], title="Choose the encode options")
choice = detail_menu.show()
else:
choice = int(opts['encode']['mode'])
# Flat, slow anime (slice of life, everything is well lit)
if choice == 1:
param_line = "crf=19.0:bframes=8:aq-mode=3:psy-rd=1:aq-strength=0.8:deblock=1,1"
#Some dark scene, some battle scene (shonen, historical, etc.)
elif choice == 2:
param_line = "crf=18.0:bframes=8:aq-mode=3:psy-rd=1.5:psy-rdoq=2"
#[TV Series] Movie-tier dark scene, complex grain/detail
elif choice == 3:
param_line = "crf=18.0:limit-sao=1:bframes=8:aq-mode=3:psy-rd=1.5:psy-rdoq=3.5"
#[Movie] Movie-tier dark scene, complex grain/detail
elif choice == 4:
param_line = "crf=16.0:limit-sao=1:bframes=8:aq-mode=3:psy-rd=1.5:psy-rdoq=3.5"
if is_tool("ffmpeg-bar"):
binary = "ffmpeg-bar"
else:
binary = "ffmpeg"
files = []
if os.path.isdir(fn):
for file in glob.glob(os.path.join(fn, "*.mkv")):
files.append(os.path.join(file))
if len(files) == 0:
cmd = [
binary,
"-hide_banner",
"-i",
fn,
"-c:v",
"libx265",
"-profile:v",
"main10",
"-pix_fmt",
"yuv420p10le",
"-preset",
"slow",
"-x265-params",
param_line,
"-map",
"0:v:0",
"-f",
"matroska",
'-vf',
'scale=out_color_matrix=bt709',
'-color_primaries',
'bt709',
'-color_trc',
'bt709',
'-colorspace',
'bt709',
out
]
subprocess.call(cmd)
else:
for f in files:
clear()
name = f.split("/")
name = name[len(name) - 1]
cmd = [
binary,
"-hide_banner",
"-i",
f,
"-c:v",
"libx265",
"-profile:v",
"main10",
"-pix_fmt",
"yuv420p10le",
"-preset",
"slow",
"-x265-params",
param_line,
"-map",
"0:v:0",
"-f",
"matroska",
'-vf',
'scale=out_color_matrix=bt709',
'-color_primaries',
'bt709',
'-color_trc',
'bt709',
'-colorspace',
'bt709',
os.path.join(out, name)
]
subprocess.call(cmd)