arut / nginx-rtmp-module

NGINX-based Media Streaming Server
http://nginx-rtmp.blogspot.com
BSD 2-Clause "Simplified" License
13.35k stars 3.51k forks source link

Adaptive HLS relay server #740

Open joelalmeida-pt opened 8 years ago

joelalmeida-pt commented 8 years ago

Hi,

I'm trying to set up a system using two remote servers (both NginX compiled with RTMP module) for streaming video between them where network conditions may be "unstable" at times.

Is it possible to somehow "pull" an adaptive HLS stream from one server to the other (acting the latter also as a relay for their own private clients) and where the stream being transmitted between both servers is the best possible according to current network bandwidth (meaning one of the several available variants in the first server) ?

I read the available documentation but I didn't see nothing which indicated how to build such a system.

Thank you!

nicktencate commented 8 years ago

You can relay to your second server using RTMP and re-create the HLS files. See hls_fragment_slicing to make them output the same file(s). https://github.com/arut/nginx-rtmp-module/wiki/Directives#hls_fragment_slicing

misiek08 commented 8 years ago

In your situation you can user fragment hooks to send chunks to second server and just serve them to clients without any further config. You will need to write a daemon that receive from first nginx information about new fragment and send them in order to second server.

2015-12-15 18:19 GMT+01:00 nicktencate notifications@github.com:

You can relay to your second server using RTMP and re-create the HLS files. See hls_fragment_slicing to make them output the same file(s).

https://github.com/arut/nginx-rtmp-module/wiki/Directives#hls_fragment_slicing

— Reply to this email directly or view it on GitHub https://github.com/arut/nginx-rtmp-module/issues/740#issuecomment-164831511 .

joelalmeida-pt commented 8 years ago

Thank you for your answers, I can see how to send the HLS stream from the first server to the second, but I can't see how to make the adaptive part.

I mean, if I relay multiple streams from the first server to the second server (each stream with a different bitrate, but with the same live video content) how will the second server choose the stream that better adapts to current network bandwidth? Thanks!

nicktencate commented 8 years ago

Ah, currently no way to do this automatically. You will have to pick one manually.

misiek08 commented 8 years ago

Your script need to be smart enough. 16 gru 2015 16:22 "nicktencate" notifications@github.com napisał(a):

Ah, currently no way to do this automatically. You will have to pick one manually.

— Reply to this email directly or view it on GitHub https://github.com/arut/nginx-rtmp-module/issues/740#issuecomment-165139699 .

joelalmeida-pt commented 8 years ago

Ok, no automatic way... any guidelines for a 'smart script'? I guess it should: 1) Measure the network status (ping time or something more accurate...?) 2) Choose the adequate bitrate stream to send from server 1 to server 2 Makes sense?

misiek08 commented 8 years ago

Ping won't tell you much about link (because you can have great pings and slow connection), but your path is good. You need to periodically test connection and upload adequate stream.

2015-12-16 17:22 GMT+01:00 joelalmeida-pt notifications@github.com:

Ok, no automatic way... any guidelines for a 'smart script'? I guess it should: 1) Measure the network status (ping time or something more accurate...?) 2) Choose the adequate bitrate stream to send from server 1 to server 2 Makes sense?

— Reply to this email directly or view it on GitHub https://github.com/arut/nginx-rtmp-module/issues/740#issuecomment-165163037 .

AlexRevin commented 8 years ago

Checkout: https://github.com/Viblast/dash-proxy https://github.com/Viblast/hls-proxy

xedsvg commented 8 years ago

http { proxy_cache_path /var/www/hls-test1/cache levels=1:2 keys_zone=hls-test1-cache:8m max_size=1000m inactive=600m; server { listen 80; server_name localhost; root /var/www/hls-test1; proxy_temp_path /var/www/hls-test1/temp; location / { proxy_pass http://ip-of-the-other-server; add_header "X-Hls-Cache-Status" "Fresh data"; } location ~* .(ts|trp)$ { proxy_pass http://ip-of-the-other-server; proxy_cache hls-test1-cache; proxy_cache_valid 200 10m; proxy_cache_valid 404 5s; add_header "X-Hls-Cache-Status" "Cached TS"; } } }

You have to tweak it, but it's more than nothing. Read the thread here

hamlatzis commented 1 year ago

Checkout: https://github.com/Viblast/dash-proxy https://github.com/Viblast/hls-proxy

these python scripts will they work if my .mpd or .m3u8 files are for multiple streams? My nginx configuration uses ffmpeg to create different quality streams depending on bandwidth