Use ffmpeg for generic cameras in go2rtc (#148818)

This commit is contained in:
Robert Resch 2025-07-15 17:38:19 +02:00 committed by GitHub
parent 5b29d6bbdf
commit 8bd51a7fd1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 0 deletions

View File

@ -306,6 +306,11 @@ class WebRTCProvider(CameraWebRTCProvider):
await self.teardown() await self.teardown()
raise HomeAssistantError("Camera has no stream source") 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): if not self.async_is_supported(stream_source):
await self.teardown() await self.teardown()
raise HomeAssistantError("Stream source is not supported by go2rtc") raise HomeAssistantError("Stream source is not supported by go2rtc")

View File

@ -670,3 +670,32 @@ async def test_async_get_image(
HomeAssistantError, match="Stream source is not supported by go2rtc" HomeAssistantError, match="Stream source is not supported by go2rtc"
): ):
await async_get_image(hass, camera.entity_id) 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",
],
)