From 1ad3c3b1e29ced7048ab16c45100ee836f08a6d7 Mon Sep 17 00:00:00 2001 From: nragon Date: Wed, 21 Nov 2018 22:12:16 +0000 Subject: [PATCH] Minor change to still image on mjpeg (#18602) * Update mjpeg.py * Lint --- homeassistant/components/camera/mjpeg.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/camera/mjpeg.py b/homeassistant/components/camera/mjpeg.py index 9db7c138182..5c6d7e18075 100644 --- a/homeassistant/components/camera/mjpeg.py +++ b/homeassistant/components/camera/mjpeg.py @@ -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):