Add H.265 support to stream component (#38125)
* Add H.265 support to stream component * Change find_box to generator * Move fmp4 utilities to fmp4utils.py * Add minimum segments and segment durations * Remove MIN_SEGMENTS * Fix when container_options is None * Fix missing num_segments and update tests * Remove unnecessary mock attribute * Fix Segment construction in test_recorder_save * fix recorder with lookback Co-authored-by: Jason Hunter <hunterjm@gmail.com>
This commit is contained in:
1 parent
d0a59e28ac
commit
5355fcaba8
11 files changed
+169
-51
No files matched your search
@@ -20,7 +20,7 @@ def generate_h264_video():
|
||||
total_frames = duration * fps
|
||||
|
||||
output = io.BytesIO()
|
||||
output.name = "test.ts"
|
||||
output.name = "test.mp4"
|
||||
container = av.open(output, mode="w")
|
||||
|
||||
stream = container.add_stream("libx264", rate=fps)
|
||||
|
||||
@@ -38,6 +38,13 @@ async def test_hls_stream(hass, hass_client):
|
||||
playlist_response = await http_client.get(parsed_url.path)
|
||||
assert playlist_response.status == 200
|
||||
|
||||
# Fetch init
|
||||
playlist = await playlist_response.text()
|
||||
playlist_url = "/".join(parsed_url.path.split("/")[:-1])
|
||||
init_url = playlist_url + "/init.mp4"
|
||||
init_response = await http_client.get(init_url)
|
||||
assert init_response.status == 200
|
||||
|
||||
# Fetch segment
|
||||
playlist = await playlist_response.text()
|
||||
playlist_url = "/".join(parsed_url.path.split("/")[:-1])
|
||||
@@ -99,15 +106,16 @@ async def test_stream_ended(hass):
|
||||
source = generate_h264_video()
|
||||
stream = preload_stream(hass, source)
|
||||
track = stream.add_provider("hls")
|
||||
track.num_segments = 2
|
||||
|
||||
# Request stream
|
||||
request_stream(hass, source)
|
||||
|
||||
# Run it dead
|
||||
segments = 0
|
||||
while await track.recv() is not None:
|
||||
segments += 1
|
||||
while True:
|
||||
segment = await track.recv()
|
||||
if segment is None:
|
||||
break
|
||||
segments = segment.sequence
|
||||
|
||||
assert segments > 1
|
||||
assert not track.get_segment()
|
||||
|
||||
@@ -72,7 +72,6 @@ async def test_record_service_lookback(hass):
|
||||
):
|
||||
# Setup stubs
|
||||
hls_mock = MagicMock()
|
||||
hls_mock.num_segments = 3
|
||||
hls_mock.target_duration = 2
|
||||
hls_mock.recv = AsyncMock(return_value=None)
|
||||
stream_mock.return_value.outputs = {"hls": hls_mock}
|
||||
|
||||
@@ -31,12 +31,11 @@ async def test_record_stream(hass, hass_client):
|
||||
recorder = stream.add_provider("recorder")
|
||||
stream.start()
|
||||
|
||||
segments = 0
|
||||
while True:
|
||||
segment = await recorder.recv()
|
||||
if not segment:
|
||||
break
|
||||
segments += 1
|
||||
segments = segment.sequence
|
||||
|
||||
stream.stop()
|
||||
|
||||
@@ -76,7 +75,7 @@ async def test_recorder_save():
|
||||
output.name = "test.mp4"
|
||||
|
||||
# Run
|
||||
recorder_save_worker(output, [Segment(1, source, 4)])
|
||||
recorder_save_worker(output, [Segment(1, source, 4, (360000, 176400))])
|
||||
|
||||
# Assert
|
||||
assert output.getvalue()
|
||||
Reference in new issue
Block a user