Skip to main content
Version: 5.0 🚧

RTMP URL/Vhost

The url of RTMP is simple, and the vhost is not a new concept, although it's easy to confuse for the fresh. What is vhost? What is app? Why FMLE should input the app and stream?

Vhost(Virtual Host) is used to seperate customers or businesses. Let's take a look at the typical use scenaio of vhost.

The benifit of RTMP and HLS, see: HLS

Use Scenario

The use scenario of vhost:

  • Multiple customers cloud: For example, CDN(content delivery network) serves multiple customers. How does CDN to seperate customer and stat the data? Maybe stream path is duplicated, for example, live/livestream is the most frequently used app and stream. The vhost, similar to the virtual server, provides abstract for multiple customers.
  • Different config: For example, FMLE publish h264+mp3, which should be transcoded to h264+aac. We can use vhost to use different config, h264+mp3 disabled hls while the h264+aac vhost enalbe hls.

In a word, vhost is the element of config, to seperate customer and apply different config.

Standard RTMP URL

Standard RTMP URL is the most compatible URL, for all servers and players can identify. The RTMP URL is similar to the HTTP URL:

HTTPSchemaHostPortAppStream
http://192.168.1.10:80/players/srs_player.htmlhttp192.168.1.1080playerssrs_player.html
rtmp://192.168.1.10:1935/live/livestreamrtmp192.168.1.101935livelivestream

It is:

  • Schema:The protocol prefix, HTTP/HTTPS for HTTP protocol, and RTMP/RTMPS/RTMPE/RTMPT for RTMP protocol, while the RTMFP is adobe flash p2p protocol.
  • Host:The server ip or dns name to connect to. It is dns name for CDN, and the dns name is used as the vhost for the specified customer.
  • Port:The tcp port, default 80 for HTTP and 1935 for RTMP.
  • Path:The http file path for HTTP.
  • App:The application for RTMP, similar to the directory of resource(stream).
  • Stream:The stream for RTMP, similar to the resource(file) in specified app.

NO Vhost

However, most user donot need the vhost, and it's a little complex, so donot use it when you donot need it. Most user actually only need app and stream.

When to use vhost? When you serve 100+ customers and use the same delivery network, they use theire own vhost and can use the sample app and stream.

The common use scenario, for example, if you use SRS to build a video website. So you are the only customer, donot need vhost. Suppose you provides video chat, there are some categories which includes some chat rooms. For example, categories are military, reader, history. The military category has rooms rock, radar; the reader category has red_masion. The config of SRS is very simple:

listen              1935;
vhost __defaultVhost__ {
}

When generate web pages, for instance, military category, all app is military. The url of chat room is rtmp://yourdomain.com/military/rock, while the encoder publish this stream, and all player play this stream.

The other pages of the military category use the same app name military, but use the different stream name, fr example, radar chat room use the stream url rtmp://yourdomain.com/military/radar.

When generate the pages, add new stream, the config of SRS no need to change. For example, when add a new chat room cannon, no need to change config of SRS. It is simple enough!

The reader category can use app reader, and the red_mansion chat room can use the url rtmp://yourdomain.com/reader/red_mansion.

Vhost Use Scenarios

The vhost of RTMP is same to HTTP virtual server. For example, the demo.srs.com is resolve to 192.168.1.10 by dns or hosts:

HTTPHostPortVhost
http://demo.srs.com:80/players/srs_player.html192.168.1.1080demo.srs.com
rtmp://demo.srs.com:1935/live/livestream192.168.1.101935demo.srs.com

The use scenario of vhost:

  • Multiple Customers: When need to serve multiple customers use the same network, for example, cctv and wasu delivery stream on the same CDN, how to seperate them, when they use the same app and stream?
  • DNS scheduler: When CDN delivery content, the fast edge for the specified user is resolved for the dns name. We can use vhost as the dns name to scheduler user to different edge.
  • Multiple Config sections: Sometimes we need different config, for example, to delivery RTMP for PC and transcode RTMP to HLS for android and IOS, we can use one vhost to delivery RTMP and another for HLS.

Multiple Customers

For example, we got two customers cctv and wasu, use the same edge server 192.168.1.10, when user access the stream of these two customers:

RTMPHostPortVhostAppStream
rtmp://show.cctv.cn/live/livestream192.168.1.101935show.cctv.cnlivelivestream
rtmp://show.wasu.cn/live/livestream192.168.1.101935show.wasu.cnlivelivestream

The config on the edge 192.168.1.10, need to config the vhost:

listen              1935;
vhost show.cctv.cn {
}
vhost show.wasu.cn {
}

DNS GSLB

Please refer to the tech for DNS and CDN.

Config Unit

For example, two customers cctv and wasu, and cctv needs mininum latency, while wasu needs fast startup.

Then we config the cctv without gop cache, and wasu config with gop cache:

listen              1935;
vhost show.cctv.cn {
chunk_size 128;
}
vhost show.wasu.cn {
chunk_size 4096;
}

These two vhosts is completely isolated.

Default Vhost

The default vhost is __defaultVhost_\ introduced by FMS. When mismatch and vhost not found, use the default vhost if configed.

For example, the config of SRS on 192.168.1.10:

listen              1935;
vhost demo.srs.com {
}

Then, when user access the vhost:

  • rtmp://demo.srs.com/live/livestream:OK, matched vhost is demo.srs.com.
  • rtmp://192.168.1.10/live/livestream:Failed, no matched vhost, and no default vhost.

The rule of default vhost is same to other vhost, the default is used for the vhost not matched and not find.

Locate Vhost

There are two ways to access the vhost on server:

  • DNS name: When access the dns name equals to the vhost, by dns resolve or hosts file, we can access the vhost on server.
  • Stream parameters: While publishing or playing stream, the parameter can take the vhost. This needs the server supports this way, for example, SRS can use parameter ?vhost=VHOST and ?domain=VHOST to access specified vhost.

For example:

RTMP URL: rtmp://demo.srs.com/live/livestream
Edge servers: 50 servers
Edge server ip: 192.168.1.100 to 192.168.1.150
Edge SRS config:
listen 1935;
vhost demo.srs.com {
mode remote;
origin: xxxxxxx;
}

The ways to access the url on edge servers:

UserRTMP URLhostsTarget
Userrtmp://demo.srs.com/live/livestream-Resolved by DNS
DevOpsrtmp://demo.srs.com/live/livestream192.168.1.100 demo.srs.comConnect to 192.168.1.100
DevOpsrtmp://192.168.1.100/live?
vhost=demo.srs.com/livestream
-Connect to 192.168.1.100
DevOpsrtmp://192.168.1.100/live
...vhost...demo.srs.com/livestream
-Connect to 192.168.1.100

It is sample way to access other servers.

Parameters in URL

There is no parameters for RTMP URL, similar to query string of HTTP, we can pass parameters in RTMP URL for SRS:

  • Vhost:Specifies the vhost in the RTMP URL for SRS.
  • Token authentication: Not implements for SRS, while user can specifies the token in the RTMP URL, SRS can fetch the token and verify it on remote authentication server. The token authentication is better and complex than refer authentication.

The parameters in SRS URL:

  • rtmp://192.168.1.100/live/livestream?vhost=demo.srs.com
  • rtmp://192.168.1.100/live/livestream?domain=demo.srs.com
  • rtmp://192.168.1.100/live/livestream?token=xxx
  • rtmp://192.168.1.100/live/livestream?vhost=demo.srs.com&token=xxx

Note: FMLE passes the parameters in app, which should not be used now, because it confuses people.

It's also applied to other protocols, for example:

  • http://192.168.1.100/live/livestream.flv?vhost=demo.srs.com&token=xxx
  • http://192.168.1.100/live/livestream.m3u8?vhost=demo.srs.com&token=xxx
  • webrtc://192.168.1.100/live/livestream?vhost=demo.srs.com&token=xxx

Note: SRT is another story, please read SRT Parameters for details.

URL of SRS

SRS always simplify the problem, never make it more complex.

The RTMP URL of SRS use standard RTMP URL. Generally do not need to modify the url or add parameters in it, except:

  • Change vhost: Manually change vhost in RTMP URL for debuging.
  • Token authentication: To support token authentication.

Furthermore, recomment user to use one level app and stream, never use multiple level app and stream. For example:

// Not recomment multiple level app and stream, which confuse people.
rtmp://demo.srs.com/show/live/livestream
rtmp://demo.srs.com/show/live/livestream/2013

The srs_player and srs_publisher donot support multiple level app and stream. Both srs_player and srs_publisher make the word behind the last / to stream, the left is tcUrl(vhost/app). For example:

// For both srs_player and srs_publisher:
// play or publish the following rtmp URL:
rtmp://demo.srs.com/show/live/livestream/2013
schema: rtmp
host/vhost: demo.srs.com
app: show/live/livestream
stream: 2013

It simplify the url, the palyer and publisher only need user to input a url, not tcUrl and stream.

The RTMP URL of SRS:

URLDescription
rtmp://demo.srs.com/live/livestreamStandard RTMP URL
rtmp://192.168.1.10/live/livestream?vhost=demo.srs.comURL specifies vhost
rtmp://demo.srs.com/live/livestream?key=ER892ID839KD9D0A1D87DURL specifies token authentication

Example Vhosts in SRS

The full.conf of conf of SRS contains many vhost, which used to show each feature. All features is put into the vhost demo.srs.com:

CategoryVhostDescription
RTMPdefaultVhostDefault Vhost, only RTMP.
RTMPchunksize.vhost.comSample to set the chunk_size.
Forwardsame.vhost.forward.vhost.comSample for Foward stream to the same vhost.
HLSwith-hls.vhost.comSample for HLS.
HLSno-hls.vhost.comSample to disable the HLS.
RTMPmin.delay.comSample to config the minimum latency for RTMP.
RTMPrefer.anti_suck.comSample for Refer anti-suck DRM.
RTMPremoved.vhost.comSample to disable vhost.
Callbackhooks.callback.vhost.comSample for http callback.
Transcodemirror.transcode.vhost.comSample for transcode, to use the sample filter of FFMPEG.
Transcodecrop.transcode.vhost.comSample for transcode, to use the crop filter of FFMPEG.
Transcodelogo.transcode.vhost.comSample for transcode, to use the logo filter of FFMPEG.
Transcodeaudio.transcode.vhost.comSample for transcode, to transcode audio only.
Transcodecopy.transcode.vhost.comSample for transcode, demux and mux.
Transcodeall.transcode.vhost.comSample for transcode, all transcode features.
Transcodeffempty.transcode.vhost.comSample for empty transcode, display the parameters.
Transcodeapp.transcode.vhost.comSample for transcode, transcode specified app streams.
Transcodestream.transcode.vhost.comSample for transcode, transcode specified streams.

The demo.conf of conf of SRS, used for demo of SRS。

CategoryVhostDescription
DEMOplayersThe vhost for default stream of srs_player, ingest this stream.
DEMOplayers_pubThe vhost for the srs_publisher to publish stream to.
DEMOplayers_pub_rtmpThe low latency vhost for demo.
DEMOdemo.srs.comThe full features for demo.
OthersdevThe vhost for dev, ignore.

Winlin 2014.10