-
Notifications
You must be signed in to change notification settings - Fork 13
/
presets.py
91 lines (85 loc) · 2.76 KB
/
presets.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
import os.path
from collections import OrderedDict
# SEGMENTS DURATION (seconds)
SEGMENT_SIZE = 1
# FFMPEG PRESET [ultrafast,superfast, veryfast, faster, fast, medium, slow, slower, veryslow]
FFMPEG_PRESET = 'slow'
# PRESETS FOR ADAPTATIVE QUALITY
PROFILES = OrderedDict()
PROFILES['0-ugly'] = {
'resolutions': { '4/3': '400x300', '16/9': '416x234' },
'audiobitrate': '64k',
'videobitrate': '100k',
'buffersize': '200k',
'profile': 'baseline',
'level': '3.0',
'fps': 10
}
PROFILES['1-bad'] = {
'resolutions': { '4/3': '400x300', '16/9': '416x234' },
'audiobitrate': '64k',
'videobitrate': '200k',
'buffersize': '400k',
'profile': 'baseline',
'level': '3.0',
'fps': 15
}
PROFILES['2-poor'] = {
'resolutions': { '4/3': '480x360', '16/9': '480x270' },
'audiobitrate': '64k',
'videobitrate': '400k',
'buffersize': '800k',
'profile': 'baseline',
'level': '3.0',
'fps': 15
}
PROFILES['3-low'] = {
'resolutions': { '4/3': '640x480', '16/9': '640x360' },
'audiobitrate': '96k',
'videobitrate': '600k',
'buffersize': '1200k',
'profile': 'baseline',
'level': '3.0',
'fps': 24
}
PROFILES['4-medium'] = {
'resolutions': { '4/3': '640x480', '16/9': '640x360' },
'audiobitrate': '96k',
'videobitrate': '1200k',
'buffersize': '2400k',
'profile': 'baseline',
'level': '3.1',
'fps': 24
}
PROFILES['5-high'] = {
'resolutions': { '4/3': '960x720', '16/9': '960x540' },
'audiobitrate': '128k',
'videobitrate': '3500k',
'buffersize': '7000k',
'profile': 'main',
'level': '3.1',
'fps': 24
}
PROFILES['6-hd'] = {
'resolutions': { '4/3': '1280x960', '16/9': '1280x720' },
'audiobitrate': '128k',
'videobitrate': '5000k',
'buffersize': '10000k',
'profile': 'main',
'level': '3.1',
'fps': 24
}
def build(inputfile, ratio='16/9', segmentsize=False, ffmpegmode=False):
presets = PROFILES.copy()
for quality, profile in presets.items():
try:
presets[quality]['resolution'] = profile['resolutions'][ratio]
presets[quality]['gop'] = presets[quality]['fps'] * SEGMENT_SIZE
presets[quality]['inputfile'] = inputfile
presets[quality]['outputname'] = quality
presets[quality]['segmentsize'] = segmentsize if segmentsize else SEGMENT_SIZE
presets[quality]['ffmpegmode'] = ffmpegmode if ffmpegmode else FFMPEG_PRESET
except Exception as e:
print 'Error while building {0} Profile with ratio {1}.. Ignoring'.format(quality, ratio)
del presets[quality]
return presets.items()