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