fHDHR_plugin_stream_opencv/__init__.py
deathbybandaid e2ca201cb2 test
2022-01-25 09:05:09 -05:00

51 lines
1.2 KiB
Python

import cv2
from io import BytesIO
# from fHDHR.exceptions import TunerError
class Plugin_OBJ():
def __init__(self, fhdhr, plugin_utils, stream_args, tuner):
self.fhdhr = fhdhr
self.plugin_utils = plugin_utils
self.stream_args = stream_args
self.tuner = tuner
def get(self):
def generate():
chunk_counter = 0
vid_cap = cv2.VideoCapture(self.stream_args["stream_info"]["url"])
try:
while (vid_cap.isOpened()):
chunk_counter += 1
self.fhdhr.logger.debug("Reading Chunk #%s" % chunk_counter)
grabbed, frame = vid_cap.read()
# check if frame empty
if not grabbed:
break
if not frame:
break
chunk = BytesIO()
chunk.write(frame)
yield chunk.getvalue()
except Exception as err:
self.fhdhr.logger.error("Chunk #%s unable to process: %s" % (chunk_counter, err))
finally:
vid_cap.release()
return generate()