mirror of
https://github.com/home-assistant/core.git
synced 2025-07-07 21:37:07 +00:00
parent
3d178708fc
commit
1ad3c3b1e2
@ -59,14 +59,15 @@ async def async_setup_platform(hass, config, async_add_entities,
|
||||
|
||||
def extract_image_from_mjpeg(stream):
|
||||
"""Take in a MJPEG stream object, return the jpg from it."""
|
||||
data = b''
|
||||
data = bytes()
|
||||
data_start = b"\xff\xd8"
|
||||
data_end = b"\xff\xd9"
|
||||
for chunk in stream:
|
||||
end_idx = chunk.find(data_end)
|
||||
if end_idx != -1:
|
||||
return data[data.find(data_start):] + chunk[:end_idx + 2]
|
||||
|
||||
data += chunk
|
||||
jpg_start = data.find(b'\xff\xd8')
|
||||
jpg_end = data.find(b'\xff\xd9')
|
||||
if jpg_start != -1 and jpg_end != -1:
|
||||
jpg = data[jpg_start:jpg_end + 2]
|
||||
return jpg
|
||||
|
||||
|
||||
class MjpegCamera(Camera):
|
||||
|
Loading…
x
Reference in New Issue
Block a user