Dynamic pull and push in 0.9.19

Since 0.9.19 version of nginx-rtmp-module you can dynamically pull or push streams with on_play and on_publish. 3xx HTTP result code used to redirect current stream. Now if the new stream name is started with rtmp:// then it’s supposed to be RTMP URL and relay (pull/push) is created for the current client.


http {
    ...
    location /local_redirect {
        rewrite ^.*$ newname? permanent;
    }
    location /remote_redirect {
        # no domain name here, only ip
        rewrite ^.*$ rtmp://192.168.1.123/someapp/somename? permanent;
    }
    ...
}

rtmp {
    ...
    application myapp1 {
        live on;
        # stream will be redirected to 'newname'
        on_play http://localhost:8080/local_redirect;
    }
    application myapp2 {
        live on;
        # stream will be pulled from remote location
        # requires nginx >= 1.3.10
        on_play http://localhost:8080/remote_redirect;
    }
    ...
}

In the example above myapp1 uses old redirect behavior, myapp2 shows the new feature.

In myapp2 application source stream name is not changed and pull is created for the source stream name. Later clients connecting to this stream will see the video pulled by the first client. That’s identical to usual pull behavior. You can change it however by specifying notify_relay_redirect on. This will redirect pulled stream to a new (long url-like) local name. So the streams will be grouped on rtmp url.

on_publish does the same for push operation.

The feature has 2 limitations

  • RTMP URL should not contain domains names, only IP addresses
  • nginx version>=1.3.10 is required
Advertisements
  1. #1 by Trong Le on May 14, 2013 - 3:16 pm

    Hi Arut,
    Nginx_rtmp modules day as many interesting features.
    Do you implement real redirect in nginx_rtmp?
    I saw JW support for that: http://developer.longtailvideo.com/trac/browser/trunk/fl5/src/com/longtailvideo/jwplayer/media/RTMPMediaProvider.as#L594

    Thank you.

  2. #2 by Christopher Zeman on May 19, 2013 - 1:53 am

    I may be misunderstanding this, but it almost sounds like this would fit a need I have. Here’s what I want to do:

    Stream 1: Always Live (being distributed via web and via ffmpeg to other servers)
    Stream 2: Special Event (I’d like this to supersede Stream 1 on publish. In other words, anyone viewing (ffmpeg included) Stream 1 would see Stream 2 automatically.

    Basically, I’m looking to perform dynamic stream switching.

    • #3 by rarut on May 19, 2013 - 5:19 am

      Dynamic pull/push operates only on stream play/publish start when on_play/on_publish is handled. “Dynamic” means you can push and pull any remote stream, it should not be statically written in config. However it cannot be changed while stream is playing.

      If you want your clients to switch from one stream to another when the second stream appears, it’s not supported.

  3. #4 by Marvin on June 17, 2013 - 7:14 am

    Dynamic pull and push is a great feature!

    I wonder if there is any tutorial to test this functionality. Specifically, after adding the above config in the config file, which url should we use in the client to start the stream.

    For ex: If my url is rtmp://mydomain.com/live, then what should we use in the client?

    • #5 by rarut on June 17, 2013 - 4:07 pm

      You should connect to the application (APP) where you set that on_play directive.
      Stream name (STREAM) does not make big sense but it is sent to your on_play handler,
      you can use it to make up the redirect url.

      rtmp://server.com/APP/STREAM

  4. #6 by Anthony on December 7, 2013 - 9:03 am

    This is what i need i guess.

    I used to use pull, now i want to change to dynamic pull using on_play. How do i rewrite it?

    now it is pull rtmp://192.168.11.107/live playPath=aaa name=bbb;

    it could work, i just use rtmp://nginx-rtmp-server-addr/mypull and the stream name is bbb.

    • #7 by rarut on December 8, 2013 - 10:42 am

      Check stream name in http on_play handler and if name=bbb then return HTTP 300 with this header entry: “Location: rtmp://192.168.11.107/live/aaa”

  5. #8 by vineet on November 19, 2014 - 2:20 pm

    Hi,
    Does dynamic pull work like exactly like static pull? i mean if first on_play triggers a dynamic pull (by way of 3xx rtmp:// response).
    And if second play request comes in it won’t do a duplicate relay but use the one common relay (pull) initiated by first play request?

    but what if on_play again returns 3xx response to same rtmp:// as earlier, because I don’t know if this is first request. will it duplicate the pull or reuse the earlier pull ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: