mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Use ffmpeg for generic cameras in go2rtc (#148818)
This commit is contained in:
parent
5b29d6bbdf
commit
8bd51a7fd1
@ -306,6 +306,11 @@ class WebRTCProvider(CameraWebRTCProvider):
|
||||
await self.teardown()
|
||||
raise HomeAssistantError("Camera has no stream source")
|
||||
|
||||
if camera.platform.platform_name == "generic":
|
||||
# This is a workaround to use ffmpeg for generic cameras
|
||||
# A proper fix will be added in the future together with supporting multiple streams per camera
|
||||
stream_source = "ffmpeg:" + stream_source
|
||||
|
||||
if not self.async_is_supported(stream_source):
|
||||
await self.teardown()
|
||||
raise HomeAssistantError("Stream source is not supported by go2rtc")
|
||||
|
@ -670,3 +670,32 @@ async def test_async_get_image(
|
||||
HomeAssistantError, match="Stream source is not supported by go2rtc"
|
||||
):
|
||||
await async_get_image(hass, camera.entity_id)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_generic_workaround(
|
||||
hass: HomeAssistant,
|
||||
init_test_integration: MockCamera,
|
||||
rest_client: AsyncMock,
|
||||
) -> None:
|
||||
"""Test workaround for generic integration cameras."""
|
||||
camera = init_test_integration
|
||||
assert isinstance(camera._webrtc_provider, WebRTCProvider)
|
||||
|
||||
image_bytes = load_fixture_bytes("snapshot.jpg", DOMAIN)
|
||||
|
||||
rest_client.get_jpeg_snapshot.return_value = image_bytes
|
||||
camera.set_stream_source("https://my_stream_url.m3u8")
|
||||
|
||||
with patch.object(camera.platform, "platform_name", "generic"):
|
||||
image = await async_get_image(hass, camera.entity_id)
|
||||
assert image.content == image_bytes
|
||||
|
||||
rest_client.streams.add.assert_called_once_with(
|
||||
camera.entity_id,
|
||||
[
|
||||
"ffmpeg:https://my_stream_url.m3u8",
|
||||
f"ffmpeg:{camera.entity_id}#audio=opus#query=log_level=debug",
|
||||
f"ffmpeg:{camera.entity_id}#video=mjpeg",
|
||||
],
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user