|
@@ -68,6 +68,7 @@ def video2_extractor(frame_bytes: bytes):
|
|
|
|
|
|
class FrameTakeWorker:
|
|
|
def __init__(self, device_id=0, processes=3):
|
|
|
+ self.processes = processes
|
|
|
self.executor_pool = ProcessPoolExecutor(max_workers=3)
|
|
|
logger.info(self.executor_pool)
|
|
|
self.video_source = Device.from_id(device_id)
|
|
@@ -91,15 +92,20 @@ class FrameTakeWorker:
|
|
|
output = await loop.run_in_executor(self.executor_pool, video2_extractor, frame_bytes)
|
|
|
return output
|
|
|
|
|
|
- async def test(self):
|
|
|
+ async def generator_worker(self):
|
|
|
while True:
|
|
|
logger.info("get frame")
|
|
|
frame = await self.get_frame()
|
|
|
logger.info(f"{frame}")
|
|
|
- #data = await self.frame_extractor(bytes(frame))
|
|
|
- #logger.info(f"{len(data)}")
|
|
|
+ data = await self.frame_extractor(bytes(frame))
|
|
|
+ logger.info(f"{len(data)}")
|
|
|
+
|
|
|
+ async def run_workers(self):
|
|
|
+ tasks = [self.generator_worker() for _ in range(self.processes)]
|
|
|
+ await asyncio.gather(*tasks)
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- ftw = FrameTakeWorker(0)
|
|
|
- asyncio.run(ftw.test())
|
|
|
+ ftw = FrameTakeWorker(1)
|
|
|
+ asyncio.run(ftw.run_workers())
|