Add audio to stream (#38846)
* Add audio to stream component * Use container options to do most fmp4 formatting * Add test for treatment of different audio inputs * Add test for treatment of different audio inputs * pcm_mulaw frames should be s16 * Use seek to get BytesIO length * Remove unused utcnow * Remove peek_next_audio_pts * only demux audio and video packets - ignoring data and subtitle streams Co-authored-by: Jason Hunter <hunterjm@gmail.com>
This commit is contained in:
1 parent
b0974d89a6
commit
dc2d0b9297
8 files changed
+287
-196
No files matched your search
@@ -2,6 +2,7 @@
|
||||
from datetime import timedelta
|
||||
from io import BytesIO
|
||||
|
||||
import av
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.stream.core import Segment
|
||||
@@ -75,7 +76,45 @@ async def test_recorder_save():
|
||||
output.name = "test.mp4"
|
||||
|
||||
# Run
|
||||
recorder_save_worker(output, [Segment(1, source, 4, (360000, 176400))])
|
||||
recorder_save_worker(output, [Segment(1, source, 4)], "mp4")
|
||||
|
||||
# Assert
|
||||
assert output.getvalue()
|
||||
|
||||
|
||||
@pytest.mark.skip("Flaky in CI")
|
||||
async def test_record_stream_audio(hass, hass_client):
|
||||
"""
|
||||
Test treatment of different audio inputs.
|
||||
|
||||
Record stream output should have an audio channel when input has
|
||||
a valid codec and audio packets and no audio channel otherwise.
|
||||
"""
|
||||
await async_setup_component(hass, "stream", {"stream": {}})
|
||||
|
||||
for a_codec, expected_audio_streams in (
|
||||
("aac", 1), # aac is a valid mp4 codec
|
||||
("pcm_mulaw", 0), # G.711 is not a valid mp4 codec
|
||||
("empty", 0), # audio stream with no packets
|
||||
(None, 0), # no audio stream
|
||||
):
|
||||
with patch("homeassistant.components.stream.recorder.recorder_save_worker"):
|
||||
# Setup demo track
|
||||
source = generate_h264_video(
|
||||
container_format="mov", audio_codec=a_codec
|
||||
) # mov can store PCM
|
||||
stream = preload_stream(hass, source)
|
||||
recorder = stream.add_provider("recorder")
|
||||
stream.start()
|
||||
|
||||
while True:
|
||||
segment = await recorder.recv()
|
||||
if not segment:
|
||||
break
|
||||
last_segment = segment
|
||||
|
||||
result = av.open(last_segment.segment, "r", format="mp4")
|
||||
|
||||
assert len(result.streams.audio) == expected_audio_streams
|
||||
result.close()
|
||||
stream.stop()
|
||||
Reference in new issue
Block a user