Use stream to generate fallback image for onvif (#75584)

This commit is contained in:
uvjustin 2022-08-09 22:41:19 +08:00 committed by GitHub
parent 2b2ea3dd73
commit 891158f332
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -136,13 +136,16 @@ class ONVIFCameraEntity(ONVIFBaseEntity, Camera):
self, width: int | None = None, height: int | None = None
) -> bytes | None:
"""Return a still image response from the camera."""
image = None
if self.stream and self.stream.keepalive:
return await self.stream.async_get_image(width, height)
if self.device.capabilities.snapshot:
try:
image = await self.device.device.get_snapshot(
self.profile.token, self._basic_auth
)
return image
except ONVIFError as err:
LOGGER.error(
"Fetch snapshot image failed from %s, falling back to FFmpeg; %s",
@ -150,17 +153,14 @@ class ONVIFCameraEntity(ONVIFBaseEntity, Camera):
err,
)
if image is None:
assert self._stream_uri
return await ffmpeg.async_get_image(
self.hass,
self._stream_uri,
extra_cmd=self.device.config_entry.options.get(CONF_EXTRA_ARGUMENTS),
width=width,
height=height,
)
return image
assert self._stream_uri
return await ffmpeg.async_get_image(
self.hass,
self._stream_uri,
extra_cmd=self.device.config_entry.options.get(CONF_EXTRA_ARGUMENTS),
width=width,
height=height,
)
async def handle_async_mjpeg_stream(self, request):
"""Generate an HTTP MJPEG stream from the camera."""