From 87612cd56cad1189ae7f55fa795c695709d330ef Mon Sep 17 00:00:00 2001 From: Justin Wong <46082645+uvjustin@users.noreply.github.com> Date: Sat, 10 Oct 2020 08:59:14 +0000 Subject: [PATCH 1/2] Cap AVC profile level at 4.1 --- homeassistant/components/stream/fmp4utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/stream/fmp4utils.py b/homeassistant/components/stream/fmp4utils.py index dc929e531c1c66..1838b3fc88b5b1 100644 --- a/homeassistant/components/stream/fmp4utils.py +++ b/homeassistant/components/stream/fmp4utils.py @@ -70,7 +70,8 @@ def get_codec_string(segment: io.BytesIO) -> str: ): profile = stsd_box[111:112].hex() compatibility = stsd_box[112:113].hex() - level = stsd_box[113:114].hex() + # Cap level at 4.1 for compatibility with some Google Cast devices + level = hex(min(stsd_box[113], 41))[2:] codec += "." + profile + compatibility + level # Handle H265 From 4ae629135573fba23b2488d1293e9b3e4379a5b9 Mon Sep 17 00:00:00 2001 From: Justin Wong <46082645+uvjustin@users.noreply.github.com> Date: Sun, 11 Oct 2020 08:52:19 +0000 Subject: [PATCH 2/2] Use smaller multiplier in bandwidth calculation --- homeassistant/components/stream/hls.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/stream/hls.py b/homeassistant/components/stream/hls.py index 09729f79ada099..92801c4807f090 100644 --- a/homeassistant/components/stream/hls.py +++ b/homeassistant/components/stream/hls.py @@ -32,10 +32,11 @@ class HlsMasterPlaylistView(StreamView): def render(track): """Render M3U8 file.""" # Need to calculate max bandwidth as input_container.bit_rate doesn't seem to work - # Calculate file size / duration and use a multiplier to account for variation + # Calculate file size / duration and use a small multiplier to account for variation + # hls spec already allows for 25% variation segment = track.get_segment(track.segments[-1]) bandwidth = round( - segment.segment.seek(0, io.SEEK_END) * 8 / segment.duration * 3 + segment.segment.seek(0, io.SEEK_END) * 8 / segment.duration * 1.2 ) codecs = get_codec_string(segment.segment) lines = [