-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accelerating HLS via CDN? #15
Comments
not sure that I understand the purpose for doing so.. you say "accelerate", but that doesn't make any sense..
|
The issue I’m facing is that the original stream has a slight but very visible delay whenever I play it in a browser, such as Safari and the video tag just displays a black screen.When I play the proxied link from HLS Proxy, the delay is even more noticeable. What I would like to achieve is to eliminate this delay when playing HLS Proxy streams, so that the video is available immediately each time. I initially thought about using a CDN but would you have any suggestions on a better approach? :)Thank You!On Oct 4, 2022, at 03:54, Warren Bank ***@***.***> wrote:
not sure that I understand the purpose for doing so..
you say "accelerate", but that doesn't make any sense..
since pushing video segments to a CDN takes time..
and is only meaningful if the actual purpose was to copy a live stream for distribution to a wide audience for vod (video on demand).
is it possible? yes (best to use custom hooks to implement specialized logic)
is it a very unusual use-case? yes
are there better tools for this purpose? ..probably?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***>
|
again, I'm not 100% sure of what you mean.. if by "delay", you mean "time to first byte", then there's nothing you can do.. since you can't speed up the video host server. And, of course, by adding a proxy (ie: man in the middle).. you're slowing down the speed to first byte, rather than speeding it up. if by "delay", you mean that there's stutter during playback because there's a delay between when the current video segment finishes playback and when the next video segment has been downloaded (by the video player) and is available for playback.. creating a noticeable break in the video playback, then using the "prefetch" option of the proxy should be able to help. There are caveats to this, such as the server being configured to return "HTTP 429 Too Many Requests" for a very brief period of time following each response.. which I've observed in the wild.. which can be configured incorrectly.. such that when the video player re-requests the manifest to obtain the next batch of video segments in anticipation that the currently playing batch of video segments are nearly finished playing.. the server refuses for too long.. and forces this type of "delay".. in which case, there's nothing to be done.. since you can't reconfigure the video host server. |
I've attached a screen recording below: In the recording, you can see that the when loading the proxied M3U8 link, the .ts file takes several seconds to load. This occurs each time the link is played, and sometimes the delay can be 6 - 8 seconds. Would be possible to cache this .ts file periodically using a CDN so that the loading time for the .ts file is reduced? This is what I'm trying to achieve. |
I just watched the video that shows the network waterfall diagram in Chrome DevTools.. Your performance looks pretty great to me..
I'm not sure if you've configured the proxy to prefetch all of the ts video segments in the m3u8 manifest, Which aspect of this waterfall do you think is experiencing a "delay"? |
I cheated, and used an online download time calculator.. My neighborhood is waiting (like Godot) for fiber.. still stuck on DSL. |
I've attached a screen recording of what currently happens when proxied streams are loaded: As you can see from the video, there's about a five second delay before the video starts to play, where the first .ts file needs to be loaded. Even with the prefetch option turned on, I've noticed that when accessing the same link but from a different device or just via 4G, this delay still occurs. If the prefetch and cache options are turned on, in theory shouldn't accessing the same link but via different devices no longer require five seconds to load the initial .ts file, since it's already cached? |
What I was referring to "accelerating via CDN", is that would it be possible to store this initial .ts file in a CDN, rather than fetching it from my origin server each time, since user's locations won't always be near to my origin server. Storing on CDN means that user's get the cached .ts file from their nearest CDN node rather than waiting to fetch from my server. |
This is my settings for the proxy: When using the same client / browser to access the target link after the first attempt, the loading speed is indeed very fast. But when I access the same target link with a different client on a different network with comparable speeds, immediately after the above step, then it still takes about five seconds for the video to load. Isn't the second client also supposed to receive the video very fast since it's already cached in RAM? |
If both clients are using a single/common proxy server, then identical requests will be processed in an identical way. The proxy is stateless; there are no cookies or sessions. Things to consider:
|
PS: |
I checked and the parameters and URL remain exactly the same each time. Since I'm using the proxied link, shouldn't the same link be pushed for both clients? If I would like to push the proxy stream to a CDN, is there any modification to the HLS Proxy code that I need to make or is just a server configuration? |
hmm..
In any case, an improvement that I could make to the proxy would be..
This would allow the first chunk to download at full speed (rather than sharing bandwidth with a ton of other simultaneous download requests), and return it to the video player much faster. Using the numbers from your 2x examples above:
|
fwiw, personally.. some initial latency doesn't bother me; |
to answer your question..
seems to me that:
Though, to be clear.. I wouldn't recommend doing this. |
micro-optimization: =================== * when all of the following are true: - the HLS manifest for a live stream is proxied - prefetch is enabled - the cache is empty * rather than: - immediately initiating (up to "--max-segments") parallel downloads to populate the cache, while the video player waits for the 1st video segment to become available * modify the order of downloads such that: - the 1st video segment in the manifest is immediately downloaded - once this 1st video segment is available, then all of the remaining (up to "--max-segments") in the manifest begin to download in parallel reason for change: ================== * this should reduce the latency when a live video first starts playing, since the 1st video segment downloads more quickly using all available bandwidth * when a batch of downloads occur in parallel, the available bandwidth is shared (more or less) equally; all downloads occur at a reduced rate, and complete at about the same time cross-reference: ================ * related discussion in issue #15
I just took a look at the code.. and implemented the improvement that I speculated about (above); I'd be curious to see your waterfall diagram loading the same live stream with prefetch (as the earlier screenshot).. |
I updated to the latest version and tried with this command: It seems that the prefetch option isn't doing anything anymore. Previously after the first initial playback, any subsequent reloads on the same client results in the video playing also immediately. But in the new screen recording attached below, each time the page is reloaded, the video doesn't play immediately. Is this normal? |
could you try this: ..and attach a copy of I did test this update.. and confirmed that it works precisely as desired (by inspecting terminal output in combination with a few additional logging statements). So.. to really see what's going on with your sample stream.. I need to inspect a log file. |
oh.. and to keep the size of your log file minimal.. please only load your stream once.. and allow it to run for about 45 seconds before killing the process. thanks. |
Okay here is the link to the log file: |
summary:
notes:
takeaway:
|
I’m using Safari on Mac OS. I just paste the m3u8 link directly in browser and let it play. Does that mean using Safari and playing the proxied steam nullifies the cache? |
I'm not an Apple/Mac user.. and I wasn't aware that Safari natively supports playing HLS streams; that's actually pretty nifty. That being said, my comments directly apply to their implementation.. which is problematic (for the sake of our demo). In the browser, I always test with Clappr in Chrome. Specifically, ..here. |
PS: to be clear, what I meant by "the new strategy was effectively nullified".. is that in this log.. the cache behaves the same as it did in v0.19.0 release. I wasn't saying that the cache was in any way disabled or not working. I only meant that download of the 1st ts video segment isn't accelerated.. as was the intended purpose for the v0.20.0 release. |
Sorry for the late reply, is there anyway to push the proxied stream to an rtmp server? |
Hi,
Is it possible to use a CDN to accelerate or cache live streams proxied by HLS proxy? I tried pointing a CDN to the server I've installed HLS-Proxy on and tried accessing the new link but I'm unable to access it somehow.
If it's possible, what would be the steps to get CDN working?
Thank You!
The text was updated successfully, but these errors were encountered: