-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdasher.py
More file actions
57 lines (45 loc) · 1.64 KB
/
dasher.py
File metadata and controls
57 lines (45 loc) · 1.64 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
54
55
56
57
import os
import subprocess
import sys
import adaptive_streamer
class DASHMaker:
def __init__(self, input_file, num_streams):
self.input_file = input_file
self.num_streams = num_streams
self.filenames = []
self.frag_filenames = []
self.cwd = os.path.abspath(os.path.dirname(__file__))
def create_unfragmented_files(self):
video_codec = "libx264"
audio_codec = "copy"
preset = "medium"
init_crf = 18
init_factor = 1
streamer = adaptive_streamer.AdaptiveStreamer(self.input_file, self.num_streams, video_codec,
audio_codec, preset, init_crf, init_factor)
streamer.create_all_streams()
self.filenames = streamer.get_filenames()
def create_fragmented_files(self):
for file in self.filenames:
out_file = file[:-4] + "f" + ".mp4"
subprocess.run(["mp4fragment", file, out_file], shell=True, cwd=self.cwd)
self.frag_filenames.append(out_file)
def create_dash_stream(self):
self.create_unfragmented_files()
self.create_fragmented_files()
subprocess.run(["mp4dash"] + self.frag_filenames, shell=True, cwd=self.cwd)
def clean_up(self):
os.chdir(self.cwd)
for file in self.filenames:
os.remove(file)
for file in self.frag_filenames:
os.remove(file)
def run(self):
self.create_dash_stream()
self.clean_up()
def main():
input_file = sys.argv[1]
num_streams = int(sys.argv[2])
dash_maker = DASHMaker(input_file, num_streams)
dash_maker.run()
main()