-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
79 lines (61 loc) · 2.4 KB
/
run.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
import sys
import time
from multiprocessing import Pool
from transcoder import Transcoder
def transsize(transcoder, height, aspect_ratio):
start = time.time()
transcoder.transsize(height, aspect_ratio)
print("Transsize time, no chunking: {:0.2f}".format(time.time() - start))
def chunked_transsize(transcoder, height, aspect_ratio, workers):
# Split
start = time.time() # TODO: decorate methods with timer
transcoder.split(workers)
split_time = time.time() - start
# Scale
transsize_time_worst_case = 0
for chunk_file in t.chunk_files:
start = time.time()
transcoder.transsize(height, aspect_ratio, chunk_file)
transsize_time_worst_case = max(time.time() - start, transsize_time_worst_case)
# Stitch
start = time.time()
transcoder.stitch()
stitch_time = time.time() - start
print("Transsize time with chunking: {:0.2f}".format(split_time + transsize_time_worst_case + stitch_time))
def parallel_chunked_transsize(transcoder, height, aspect_ratio, workers):
"""
Will not work as a method for estimating distributed transcode time.
"""
start = time.time()
transcoder.split(workers)
with Pool(processes=workers) as pool:
pool.starmap(transcoder.transsize, [(height, aspect_ratio, f) for f in t.chunk_files])
transcoder.stitch()
print("Transsize time with chunking: {:0.2f}".format(time.time() - start))
def seek_split(transcoder, workers):
start = time.time()
chunk_time = transcoder.get_chunk_time(workers)
for i in range(workers):
transcoder.seek_split(i, chunk_time)
print("Split time: {:0.2f}".format(time.time() - start))
def parallel_seek_split(transcoder, workers):
"""
Offers a marginal increase in speed.
"""
start = time.time()
chunk_time = transcoder.get_chunk_time(workers)
with Pool(processes=workers) as pool:
pool.starmap(transcoder.seek_split, [(i, chunk_time) for i in range(workers)])
print("Split time: {:0.2f}".format(time.time() - start))
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: TODO")
sys.exit(1)
t = Transcoder(sys.argv[1])
transsize_args = (720, 16 / 9)
workers = 5 # TODO: sys.arg --workers -w
t.split(workers)
# transsize(t, *transsize_args)
# chunked_transsize(t, *transsize_args, workers)
# seek_split(t, workers)
# parallel_seek_split(t, workers)