Minor change to still image on mjpeg (#18602)

* Update mjpeg.py

* Lint
This commit is contained in:
nragon 2018-11-21 22:12:16 +00:00 committed by Paulus Schoutsen
parent 3d178708fc
commit 1ad3c3b1e2

View File

@ -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):