-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.py
51 lines (40 loc) · 1.71 KB
/
configuration.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
import json
class Profile:
scales = {"720p": "-1:720", "1080p": "-1:1080"}
def __init__(self, profile):
self.profile = profile
def build_params(self):
bitrate = self.profile["bitrate"]
br_multiple = self.profile["br_variable"] / 100
params = ["-vf", "scale={scale}".format(scale=self.scales[self.profile["size"]]),
"-c:v", "{codec}".format(**self.profile),
"-b:v", "{bitrate}k".format(bitrate=bitrate),
"-maxrate", "{maxrate}k".format(maxrate=bitrate*br_multiple),
"-bufsize", "{bufsize}k".format(bufsize=bitrate*br_multiple),
"-profile:v", "{profile_name}".format(**self.profile),
"-x264-params", "bframes={bframes}".format(**self.profile),
"-c:a", "copy"]
return params
def build_output_file_name(self):
br_variable = self.profile["br_variable"]
if br_variable > 100:
br_mode = '{percent}BR'.format(percent=br_variable)
else:
br_mode = 'CBR'
output_file_name = '{codec}_{size}_{bitrate}k_{profile_name}_bf{bframes}_{br_mode}'.format(**self.profile,br_mode=br_mode)
return output_file_name
class Configuration:
def __init__(self, ffmpeg_tools, hwaccel, output_dir, profiles, metrics):
self.ffmpeg_tools = ffmpeg_tools
self.hwaccel = hwaccel
self.output_dir = output_dir
self.profiles = []
for item in profiles:
self.profiles.append(Profile(item))
self.metrics = metrics
def prepare_config(args):
with open(args.config) as json_file:
data = json.load(json_file)
config = Configuration(**data)
print(config.output_dir)
return config