Skip to content

Commit 9e4b8df

Browse files
edenhausfrenck
authored andcommitted
Use ffmpeg for generic cameras in go2rtc (home-assistant#148818)
1 parent 69fdc1d commit 9e4b8df

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

homeassistant/components/go2rtc/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ async def _update_stream_source(self, camera: Camera) -> None:
306306
await self.teardown()
307307
raise HomeAssistantError("Camera has no stream source")
308308

309+
if camera.platform.platform_name == "generic":
310+
# This is a workaround to use ffmpeg for generic cameras
311+
# A proper fix will be added in the future together with supporting multiple streams per camera
312+
stream_source = "ffmpeg:" + stream_source
313+
309314
if not self.async_is_supported(stream_source):
310315
await self.teardown()
311316
raise HomeAssistantError("Stream source is not supported by go2rtc")

tests/components/go2rtc/test_init.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,3 +670,32 @@ async def test_async_get_image(
670670
HomeAssistantError, match="Stream source is not supported by go2rtc"
671671
):
672672
await async_get_image(hass, camera.entity_id)
673+
674+
675+
@pytest.mark.usefixtures("init_integration")
676+
async def test_generic_workaround(
677+
hass: HomeAssistant,
678+
init_test_integration: MockCamera,
679+
rest_client: AsyncMock,
680+
) -> None:
681+
"""Test workaround for generic integration cameras."""
682+
camera = init_test_integration
683+
assert isinstance(camera._webrtc_provider, WebRTCProvider)
684+
685+
image_bytes = load_fixture_bytes("snapshot.jpg", DOMAIN)
686+
687+
rest_client.get_jpeg_snapshot.return_value = image_bytes
688+
camera.set_stream_source("https://my_stream_url.m3u8")
689+
690+
with patch.object(camera.platform, "platform_name", "generic"):
691+
image = await async_get_image(hass, camera.entity_id)
692+
assert image.content == image_bytes
693+
694+
rest_client.streams.add.assert_called_once_with(
695+
camera.entity_id,
696+
[
697+
"ffmpeg:https://my_stream_url.m3u8",
698+
f"ffmpeg:{camera.entity_id}#audio=opus#query=log_level=debug",
699+
f"ffmpeg:{camera.entity_id}#video=mjpeg",
700+
],
701+
)

0 commit comments

Comments
 (0)