Friday, January 10, 2014

Redirecting streams in version 1.1.1

In version 1.1.1 of nginx-rtmp-module stream redirect feature is added. Now you can change currently played or published stream in realtime through control request. The following call changes subscriber stream name to newname. The subscriber is found in myapp application by the IP address 127.0.0.1.
http://server.com/control/redirect/subscriber?app=myapp&addr=127.0.0.1
&newname=newname
The above example changes stream for a single client. To change it for all clients use pull and change its source end. You can pull certain streams from VOD applications as well.
application myapp {
  live on;
  hls on;
  hls_path /var/hls;
  pull rtmp://localhost/src/default name=myapp static;
}

application src {
  live on; 
  pull rtmp://localhost/vod/title.mp4 name=default;
  pull rtmp://localhost/vod/ad.mp4 name=ad;
}

application vod {
  play /var/videos;
}
The myapp stream starts with title.mp4. Now switch to cam1 (which should be published to src application)
http://server.com/control/redirect/subscriber?app=src&addr=127.0.0.1
&newname=cam1
Now show ad.mp4
http://server.com/control/redirect/subscriber?app=src&addr=127.0.0.1
&newname=ad
Back to cam1
http://server.com/control/redirect/subscriber?app=src&addr=127.0.0.1
&newname=cam1
Now show cam2
http://server.com/control/redirect/subscriber?app=src&addr=127.0.0.1
&newname=cam2
The new stream starts immediately in RTMP. In HLS the stream is usually slightly delayed due to the nature of HLS.

Limitations:
  • The feature only works in single-worker mode. You can easily create a streaming backend with a single worker to pull from.
  • MPEG-DASH engine cannot handle stream discontinuities so the feature will not work properly with DASH

16 comments:

  1. This is very nice. I've been wanting to do dynamic redirection for quite some time.

    What kind of error handling does this offer? For instance if the "cam1" stream isn't connected and you try to redirect to it, what happens? Would there be a means of setting up and error handling redirect for an app to automatically redirect to if the stream doesn't exist, or if the stream cuts out for some reason?

    ReplyDelete
    Replies
    1. Error handling is not implemented now. Connecting to an idle stream is not an error by default.

      Delete
    2. Dear Roman - you are doing an excellent job with the RTM module!
      I am trying to use this feature and have difficulties. I appreciate if you'll be able to help me.

      Here is what I have in my config file:

      application myapp {
      live on;
      hls on;
      hls_path /data/hls;
      pull rtmp://localhost:1935/src/default name=myapp static;
      }

      application src {
      live on;

      pull rtmp://localhost:1935/vod/videoclip.mp4 name=default;
      pull rtmp://localhost:1935/vod/ad.mp4 name=ad;
      pull rtmp://SOMEIP:1935 app=1tv name=1tv1 static live=1 ;

      }

      in VLC I am typing rtmp://SERVERIP:1935/myapp/myapp - plays videoclip.mp4 I am typing in the browser:

      http://SERVERIP/control/redirect/subscriber?app=myapp&addr=127.0.0.1&newname=1tv1

      or

      http://SERVERIP/control/redirect/subscriber?app=myapp&addr=127.0.0.1&newname=ad

      and I don't see any switching. Each stream works fine, like rtmp://SERVERIP:1935/src/ad and rtmp://SERVERIP:1935/src/1tv1

      Can you tell me please what am I doing wrong.

      Thank you,
      George

      Delete
    3. I've just fixed a typo in the post. Instead of "app=myapp" you should use "app=src" in the control request.

      Delete
  2. sorry dono if my last post worked but http://server:8080/control/redirect/subscriber?app=live&addr=thepersonsip&name=oldchan&newname=newchan should work?

    ReplyDelete
  3. I don't quite understand where cam1 and cam2 is coming from. You say they should be published to the src application but how would you do that?

    ReplyDelete
  4. in multi-worker mode can all workers poll only one stream from remote server? then it can save traffic in cdn.

    ReplyDelete
    Replies
    1. like nginx proxy_cache_lock , can rtmp do it?

      Delete
  5. Hello Roman, congrats for this amazing module on nginx, I'm just started playing around with just VOD nothing live yet but I'm curious to know of on VOD we will be able to move forward or backward the video??

    ReplyDelete
  6. Hi Roman,

    Thanks for this nginx-rtmp module, its very useful for me. I am able to record the streaming in local but want to save my recorded files in AWS S3 bucket can you please help me

    ReplyDelete
  7. Hello Roman,

    When switching the video is freeze for about one or two seconds, can we avoid this?

    ReplyDelete


  8. Hls Streaming Server


    Get to us to find high- quality hls streaming server services and great deals. We are one of the largest service providers that help you with the best hls streaming server services. Visit us to see what we have to offer.


    https://cdn.net/how-cdns-facilitate-faster-http-live-streaming/

    ReplyDelete
  9. lütfen yardımcı olabilir misiniz ben kurulumu yapamıyorum

    ReplyDelete
  10. One of the most mind-blowing free live games ongoing elements you've never known about is Streameast. Streameast Live moreover has a lot of components, which is remarkable for free games online element

    ReplyDelete
  11. Utilizing a VPN makes it very easy to stream streameast vpn live safely online. In nations with strict anti-piracy laws and restrictions, StreamEast is restricted. So, in order to watch your favourite team compete at StreamEast, you must use a VPN if you live in a nation with strict anti-piracy laws.

    ReplyDelete
  12. You are truly talented! Your creativity and skill are apparent in everything you do. I recently wrote a profile Color Blind Test  that I'm really proud of. I'd love for you to check it out and let me know what you think! Color blind tests remind us that there are different ways to see the world and that diversity extends beyond what we perceive.

    ReplyDelete