From e2182db95cb99e74ceed6c1dab995491c1f4914c Mon Sep 17 00:00:00 2001 From: nragon Date: Tue, 20 Nov 2018 22:50:49 +0000 Subject: [PATCH 1/2] Update mjpeg.py --- 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 6168eb81939a2..8ca799cb186b7 100644 --- a/homeassistant/components/camera/mjpeg.py +++ b/homeassistant/components/camera/mjpeg.py @@ -52,14 +52,15 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): 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): From 68be03cc54fdaa858fa5862216b6bc909577ea18 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 21 Nov 2018 20:58:12 +0100 Subject: [PATCH 2/2] Lint --- homeassistant/components/camera/mjpeg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/camera/mjpeg.py b/homeassistant/components/camera/mjpeg.py index 8ca799cb186b7..899affef071ff 100644 --- a/homeassistant/components/camera/mjpeg.py +++ b/homeassistant/components/camera/mjpeg.py @@ -59,7 +59,7 @@ def extract_image_from_mjpeg(stream): end_idx = chunk.find(data_end) if end_idx != -1: return data[data.find(data_start):] + chunk[:end_idx + 2] - + data += chunk