I want to request multipart streaming by using API of Python and show it on the entity of the camera…
This url can work on the web, it can show a video stream on the web, and when I can
request it, it will return bytes of the stream, but I don’t know to extract frames from the stream data,
So I use package of pyav, and it can extract the frame successfully. I know it’s not a good
solution, but I have no idea to fix it, and I use it to create a camera. Then the image can show
on the entity, but the stream of camera doesn’t work, it only refreshes once ten second, what
can I modify my code that my entity can work successfully. I’ve been researching a lot of documentation and examples and have been stuck for over a week…
Please help me, thanks…
I implement it after reading the doc of camera, but the function "handle_async_still_stream"
and "async def handle_async_mjpeg_stream"
seems that it doesn’t work or won’t even execute, why? And I don’t know the request
of function have to supply what. Any discussion and suggestion is helpful.
@property
def is_streaming(self):
"""Return true if the device is streaming."""
return self._attr_is_streaming
def camera_image(self, width, height):
content = "http://111.11.1.111:1234"
with av.open(content) as container:
stream = container.streams.video[0]
for frame in container.decode(stream):
img = frame.to_image()
buf = BytesIO()
img.save(buf, format='JPEG')
byte_im = buf.getvalue()
break
return byte_im
async def async_camera_image(self, width = 480, height = 360):
return await self.hass.async_add_executor_job(
partial(self.camera_image, width=width, height=height)
)
async def handle_async_still_stream(self, request, interval):
return await async_get_still_stream(
request, self.async_camera_image, self.content_type, interval
)
async def handle_async_mjpeg_stream(self, request):
return await self.handle_async_still_stream('Get', 0.1)