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
Hi Arut,
ReplyDeleteNginx_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.
I may be misunderstanding this, but it almost sounds like this would fit a need I have. Here's what I want to do:
ReplyDeleteStream 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.
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.
ReplyDeleteIf you want your clients to switch from one stream to another when the second stream appears, it's not supported.
Dynamic pull and push is a great feature!
ReplyDeleteI 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?
You should connect to the application (APP) where you set that on_play directive.
ReplyDeleteStream 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