Table of Contents |
---|
Overview
Since WCS build 5.2.1193 it is possible to publish MPEG-TS RTP stream via UDP to WCS, and since build 5.2.1253 MPEG-TS stream may be published via SRT. The feature can be used to publish H264+AAC stream from software or hardware encoder supporting MPEG-TS.
SRT protocol is more reliable than UDP, so it is recommended to use SRT for MPEG-TS publishing if possible.
Codecs supported
- H264
- AAC
Operation flowchart
1. Publisher sends REST API query /mpegts/startup
...
5. Browser receives WebRTC stream and plays it on web page.
Testing
1. For test we use:
- WCS server
- ffmpeg to publish MPEG-TS stream
- Player web application in Chrome browser to play the stream
2. Send /mpegts/startup
query with stream name test
SRT:
Code Block | ||||
---|---|---|---|---|
| ||||
curl -H "Content-Type: application/json" -X POST http://test1.flashphoner.com:8081/rest-api/mpegts/startup -d '{"localStreamName":"test","transport":"srt"}' |
UDP:
Code Block | ||||
---|---|---|---|---|
| ||||
curl -H "Content-Type: application/json" -X POST http://test1.flashphoner.com:8081/rest-api/mpegts/startup -d '{"localStreamName":"test","transport":"udp"}' |
Where test1.flashphoner.com
- WCS server address
3. Receive 200 OK
response
SRT:
Code Block | ||||
---|---|---|---|---|
| ||||
{ "localMediaSessionId": "32ec1a8e-7df4-4484-9a95-e7eddc45c508", "localStreamName": "test", "uri": "srt://test1.flashphoner.com:31014", "status": "CONNECTED", "hasAudio": true, "hasVideo": true, "record": false, "timeout": 90000, "maxTimestampDiff": 90000 } |
UDP:
Code Block | ||||
---|---|---|---|---|
| ||||
{ "localMediaSessionId": "32ec1a8e-7df4-4484-9a95-e7eddc45c508", "localStreamName": "test", "uri": "udp://test1.flashphoner.com:3100631014", "status": "CONNECTED", "hasAudio": true, "hasVideo": true, "record": false, "timeout": 90000, "maxTimestampDiff": 90000 } |
4. Publish MPEG-TS stream using URI from the response
SRT:
Code Block | ||||
---|---|---|---|---|
| ||||
ffmpeg -re -i bunny360p.mp4 -c:v libx264 -c:a aac -b:a 160k -bsf:v h264_mp4toannexb -keyint_min 60 -profile:v baseline -preset veryfast -f mpegts "srt://test1.flashphoner.com:31014" |
UDP:
Code Block | ||||
---|---|---|---|---|
| ||||
ffmpeg -re -i bunny360p.mp4 -c:v libx264 -c:a aac -b:a 160k -bsf:v h264_mp4toannexb -keyint_min 60 -profile:v baseline -preset veryfast -f mpegts "udp://test1.flashphoner.com:3100631014?pkt_size=1316" |
5. Open Player web application. Set the stream name test
to "Stream name" field and click "Start" button. Stream playback will start
Configuration
Stop stream publishing if there are no media data
By default, MPEG-TS stream publishing will stop at server side if server doe not receive any media data from publisher in 90 seconds. The timeout is set in milliseconds by the following papameter
Code Block | ||
---|---|---|
| ||
mpegts_stream_timeout=90000 |
Close subscribers sessions if publisher stops sending media data
If publisher stopped sending media data by some reason, then started again (for example, ffmpeg was restarted), the stream frame timestamps sequence is corrupting. Te stream cannot be played via WebRTC correctky in this case. As workaround, all the subscribers sessions will be closed if stream timestamps sequence corruption occurs, then all the si=ubscribers should connect to the stream again. A maximum timestamp difference is set in seconds by the following parameter
Code Block | ||
---|---|---|
| ||
mpegts_max_pts_diff=1 |
REST API
A REST-query should be HTTP/HTTPS POST request as follows:
- HTTP: http://test.flashphoner.com:8081/rest-api/mpegts/startup
- HTTPS: https://test.flashphoner.com:8444/rest-api/mpegts/startup
Where:
- test.flashphoner.com - is the address of the WCS server
- 8081 - is the standard REST / HTTP port of the WCS server
- 8444 - is the standard HTTPS port
- rest-api - is the required part of the URL
- /mpegts/startup - REST mathod to use
REST methods and response states
REST method | REST query body example | REST response body example | Response states | Description | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
/mpegts/startup |
|
| 200 - OK 409 - Conflict 500 - Internal error | Start MPEG-TS publishing | ||||||||||||||
/mpegts/find |
|
| 200 – streams found 404 – streams not found 500 - Internal error | Find the MPEG-TS stream by criteria | ||||||||||||||
/mpegts/find_all |
| 200 – streams found 404 – streams not found 500 - Internal error | Find all MPEG-TS streams | |||||||||||||||
/mpegts/terminate |
| 200 - stream stopped 404 - stream not found 500 - Internal error | Stop MPEG-TS stream |
Parameters
Name | Description | Example |
---|---|---|
localStreamName | Name to set to the stream on server | test |
transport | Transport to use | srt |
uri | Endpoint URI to publish the stream | udp://192.168.1.39:3100631014 |
localMediaSessionId | Stream media session Id | 32ec1a8e-7df4-4484-9a95-e7eddc45c508 |
status | Stream status | CONNECTED |
hasAudio | Stream has audio track | true |
hasVideo | Stream has video track | true |
record | Stream is recording | false |
timeout | Maximum media data receiving timeout, ms | 90000 |
maxTimestampDiff | Maximum stream timestamps difference, ms | 90000 |
Audio only or video only publishing
Since build 5.2.1253, audio only or video only stream can be published using REST API query /mpegts/startup
parameters
- video only stream publishing
Code Block | ||||
---|---|---|---|---|
| ||||
{
"localStreamName":"mpegts-video-only",
"transport":"srt",
"hasAudio": false
} |
- audio only stream publishing
Code Block | ||||
---|---|---|---|---|
| ||||
{
"localStreamName":"mpegts-audio-only",
"transport":"srt",
"hasVideo": false
} |
Publishing audio with various samplerates
By default, the following video and audio parameters are used to publish MPEG-TS stream
Code Block | ||
---|---|---|
| ||
v=0 o=- 1988962254 1988962254 IN IP4 0.0.0.0 c=IN IP4 0.0.0.0 t=0 0 a=sdplang:en m=audio 1 RTP/AVP 102 a=rtpmap:102 mpeg4-generic/44100/2 a=sendonly m=video 1 RTP/AVP 119 a=rtpmap:119 H264/90000 a=sendonly |
Video track must be published in H264 codec with clock rate 90000 Hz, audio track must be published in AAC with samplerate 44100 Hz, two channels.
An additional samplerates or one channel may be enabled for audio publishing if necessary. Do the following to enable:
1. Create the file mpegts_agent.sdp
in /usr/local/FlashphonerWebCallServer/conf
folder
Code Block | ||||
---|---|---|---|---|
| ||||
sudo touch /usr/local/FlashphonerWebCallServer/conf/mpegts_agent.sdp |
2. Add necessary SDP parameters to the file
Code Block | ||||
---|---|---|---|---|
| ||||
sudo nano /usr/local/FlashphonerWebCallServer/conf/mpegts_agent.sdp |
for example
Code Block | ||
---|---|---|
| ||
v=0
o=- 1988962254 1988962254 IN IP4 0.0.0.0
c=IN IP4 0.0.0.0
t=0 0
a=sdplang:en
m=audio 1 RTP/AVP 102 103 104
a=rtpmap:102 mpeg4-generic/44100/2
a=rtpmap:103 mpeg4-generic/48000/2
a=rtpmap:104 mpeg4-generic/32000/1
a=sendonly
m=video 1 RTP/AVP 119
a=rtpmap:119 H264/90000
a=sendonly |
3. Set the necessary permissions and restart WCS to apply changes
Code Block | ||||
---|---|---|---|---|
| ||||
sudo nano /usr/local/FlashphonerWebCallServer/bin/webcallserver set-permissions
sudo systemctl restart webcallserver |
Known issues
1. When MPEG-TS stream publishing via UDP is stopped at server side via REST API query /mpegts/terminate
, publishing encoder still sends media data
...
Solution: this is normal behaviour for UDP because the protocol itself provides no any methods to let publisher know the UDP port is already closed. Use SRT which handles the case correctly if possible.