orion
orion copied to clipboard
twitch "low latency" support
Twitch introduced a feature for lower latency streams that channel owners can opt into. https://help.twitch.tv/customer/en/portal/articles/2935005-low-latency-video-beta
For channels that are streaming in low latency mode, the browser-based streaming video provides significantly less delay than what I currently get when watching the same channel in orion.
Investigate what transport and/or settings are used for the low latency browser streaming and if possible implement it in orion.
According to this blogpost it depends on what browser you're viewing from.
Try faking the browser agent to be "Chrome" and see if it works.
Okay, so passing &fast_bread=true
with the initial .m3u8
request for the channel gives versions of the format-specific m3u8
URLs that, when requested, have two additional lines starting with #EXT-X-TWITCH-PREFETCH:
with ts
URLs.
Re-requesting the format-specific m3u8
URL over time, the second PREFETCH
ts
URL moves to up to the first position and a new one appears in the second position. This is consistent with the web player behaviour: every 2 seconds it re-requests the format-specific m3u8
and starts loading the ts
piece in the second position. Judging by this, the PREFETCH
ts
URLs are for segments in chronological order.
When you request the first segment you get video at about the same offset to real time as you get when watching the stream in the web player when real-time streaming is enabled.
That's fine, however I haven't yet found a way to use these segments in Orion with the mpv backend that doesn't result in a hang after every segment. I'm trying to use mpv's playlist functionality, with various combinations of the prefetch-playlist
option and various cache options, and various delays before queuing future segments, in case the segment URLs are still unavailable when they first appear.
I also tried just fetching the segments directly and putting the data in mpv's playlist using its memory://
/ data://
support, but I can't get those to play anything.
Just delivering the concatenated ts segments together in an http stream for mpv with the dumbest possible proxy (https://github.com/rakslice/twitch_realtime_proxy/blob/master/twitch_realtime_proxy.py) works; we could incorporate this functionality into Orion with the existing internal web server if there's no less hackish way forward...
A prototype of that for the internal web server is at https://github.com/rakslice/orion/commit/b4b5fa663316307ee4fe69a38f989d23d55df6ab (just the mpv backend is modified to use it). That's fine as far as it goes, but I still want some way to deliver it to the video player without having to synthesize another stream.
@rakslice : status?
My implementation doesn't perform very well; the video playback often skips, and as such I don't think it's something I would ship for use by default. In practice I tend to turn it on when I want low latency for some particular reason, and then switch it off again when at some point later when I find there is a noticeable amount of skipping happening.
Also, either way, because of the proxied nature of it, it would benefit from someone else having a think about the security implications and what additional mitigations are required if any.