-
Notifications
You must be signed in to change notification settings - Fork 1
/
framer.py
75 lines (61 loc) · 2.53 KB
/
framer.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
import os
import cv2
import multiprocessing as mp
class framer(mp.Process):
def __init__(self,input_queue, output_queue):
mp.Process.__init__(self)
print("initialized init of multiprocess")
self.input_queue= input_queue
self.output_queue= output_queue
def run(self):
proc_name = self.name
print("Run initiated for proc: {}".format(proc_name))
while True:
stream_name, next_file = self.input_queue.get()
print("asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf: ", stream_name)
if next_file is None:
print("Exiting stream in {}".format(proc_name))
# self.input_queue.task_done()
break
print(proc_name, next_file)
frames_gen = frame_generator(next_file)
for frame in frames_gen:
if frame is None:
continue
# print(frame)
self.output_queue.put((stream_name, frame),)
# self.input_queue.task_done()
return
class frame_generator(object):
def __init__(self, input_data):
print("Initialised frame_generator (should happen only once)")
self.filename = input_data
self.cap = cv2.VideoCapture(self.filename)
print("filename: {}".format(self.filename))
def __iter__(self):
print("iter obj happen only once")
ret = True
while ret:
ret, frame = self.cap.read()
yield frame
def fmr(inqueue, outqueue):
inlen = len(inqueue)
consumers = [framer(inqueue[x], outqueue[x]) for x in range(inlen)]
print(consumers)
[w.start() for w in consumers]
# while True:
# print(outqueue[0].get())
return
# return (inqueue, outqueue)
if __name__ == '__main__':
#stream_ids = os.listdir(videos_path)
streams = 2
manager = mp.Manager()
framer_result = [manager.Queue() for stream in range(streams)]
inqueuelist = [manager.Queue() for stream in range(streams)]
inqueuelist[0].put(('stream1', '/home/prajwaljpj/projects/multiyolo/video/bakvid/20180818_0100_16-18-20.mp4'))
inqueuelist[0].put(('stream1', '/home/prajwaljpj/projects/multiyolo/video/bakvid/20180818_0100_16-18-21.mp4'))
inqueuelist[1].put(('stream2', '/home/prajwaljpj/projects/multiyolo/video/bakvid/20180818_0100_16-18-22.mp4'))
inqueuelist[1].put(('stream2', '/home/prajwaljpj/projects/multiyolo/video/bakvid/20180818_0100_16-18-23.mp4'))
fmr(inqueuelist, framer_result)
print(framer_result[0].get())