Publishing video to the server¶
Flussonic Media Server can accept video from external systems and devices that initiate broadcast. This is called publishing to Flussonic.
Publishing can be used in a situation where the external system has no static IP or where it is located behind the firewall in a private IP network. In this case, Flussonic has no way of directly sending a request for video.
What we call publishing to Flussonic:¶
- Transmitting video from a mobile device to Flussonic.
- Transmitting video from OBS (Open Broadcaster Software) or vMix to Flussonic. Learn more
- Transmitting video from a webpage to Flussonic via WebRTC. Learn more
What we don't call publishing to Flussonic:¶
- Receiving a multicast
- Ingesting a stream from some source
In those cases, Flussonic Media Server has to connect to the data source. Whereas the case where the connection is not initiated by Flussonic itself is called publishing. For example, publishing is when a mobile device connects to Flussonic to transmit video.
Publishing video to social networks is not publishing to Flussonic and therefore it does not meet Flussonic's definition of publishing as used in this documentation.
Supported protocols¶
Flussonic Media Server can receive requests for video publishing via the RTMP, RTSP, HTTP MPEG-TS, WebRTC, and SRT protocols.
Contents¶
- Publishing to a static stream
- Publishing with a dynamic name
- Test publication
- Protecting a publication with a password
- Authorization of a publication source
- DVR archives and dynamic names of streams
- Republishing
- Switching stream sources, using timeout
Publishing to a static stream¶
If you know what stream name an external system will use to publish video to Flussonic, you can create a stream with that name and a publish://
data source.
To create a static stream with a publishing source:
- In the admin interface, create a stream: Media > Stream > add.
- Enter a Stream name.
-
Specify
publish://
as the Source URL. Alternatively, save the stream, go to the Input tab, and set the Publication switch to enabled.Note
To disable publication to the stream, delete the
publish://
input or set the Publication switch to disabled. -
Click Create to save the stream.
- To specify additional options for a published source, click options next to the URL.
This setting corresponds to the following line in the configuration file:
stream published {
input publish://;
}
URLs for publishing via various protocols¶
To view URLs for publishing to a specific stream:
- Click the stream name in Media and go to the Input tab.
- All available URLs for publishing will be displayed in the Publish links section (see the screenshot above).
You can publish videos to Flussonic using the following URLs:
- RTSP:
rtsp://FLUSSONIC-IP/stream_name
- HTTP MPEG-TS:
http://FLUSSONIC-IP/stream_name/mpegts
- RTMP:
rtmp://flussonic-ip/published
orrtmp://flussonic-ip/static/published
. Learn more about RTMP URL at Publishing RTMP streams. - WebRTC:
http://FLUSSONIC-IP/stream_name/whip
. Learn more about publishing via WebRTC at Publishing SRT streams. - SRT:
srt://FLUSSONIC-IP:SRT_PORT?streamid=#!::r=STREAM_NAME,m=publish
. Learn more about SRT URL at Publishing SRT streams.
Publishing with a dynamic name¶
Why use dynamic names and publishing locations?¶
You might want to use dynamic names for published streams if one or more of the following is true:
- Your publications last for a limited period of time (unlike a 24/7 TV channel broadcast).
- You manage a lot of publications, and it is too much work to create a separate stream for each of them.
- You do not know the names of the incoming streams in advance. For example, you are dealing with a third-party application – like a web chat – that generates a new unique identifier for each stream that it publishes to Flussonic.
Flussonic solves these problems by allowing you to create a publishing location (publication prefix) where you can specify common settings for multiple streams.
A dynamic name means that the full name of a stream is formed from a pre-configured publication prefix and the name defined in an external app.
If the name of a published stream is not known beforehand, or if you expect many published streams, you should set up a publication prefix:
template chats {
prefix chats;
input publish://;
}
Here, chats
is the publication prefix.
All streams published under the chats
prefix will have settings that you specify in the template
directive.
To learn more about stream settings and options, refer to the Flussonic Media Server API.
You can specify several prefixes in the template
directive to create several publishing locations. You can also specify an empty prefix (""
) to publish a stream with any prefix or even without a prefix. Learn more at Templates and prefixes.
URLs for publishing via different protocols¶
In case of publishing with a dynamic name, you will need to publish streams under names with a prefix, for example:
- RTSP:
rtsp://FLUSSONIC-IP/template_name/stream_name
- HTTP MPEG-TS:
http://FLUSSONIC-IP/template_name/stream_name/mpegts
- RTMP:
rtmp://FLUSSONIC-IP/template_name/stream_name
. Learn more about RTMP URL at Publishing RTMP streams. - SRT:
srt://FLUSSONIC-IP:SRT_PORT?streamid=#!::m=publish
. Publishing via SRT with a dynamic name is only supported for this URL format, i.e. when separate port for a stream or a group of streams is set. - WebRTC:
http://FLUSSONIC-IP:PORT/template_name/stream_name/whip
.
The part of the name that goes after template_name
is defined in the client app. Flussonic Media Server does not "know" the stream name in advance.
Testing a publication¶
Publishing via RTMP¶
To test that publishing over RTMP works, you can use ffmpeg
:
ffmpeg -re -i /opt/flussonic/priv/bunny.mp4 -vcodec copy -acodec copy -f flv rtmp://localhost/chats/tmp
This command should cause a new stream to appear in the web interface:
Learn more about RTMP publishing URL at Publishing RTMP streams.
Publishing via RTSP¶
Some clients can publish video over RTSP.
Flussonic Media Server supports automatic selection between UDP and TCP transport and will receive the stream using the protocol selected by the client.
The stream name must be complete: chats/my/chat-15
ffmpeg -re -i /opt/flussonic/priv/bunny.mp4 -vcodec copy -acodec copy -f rtsp rtsp://localhost/chats/my/chat-15
Publishing via MPEG-TS¶
When transcoding a stream using ffmpeg
, it is possible to publish video over HTTP.
Video can be published with mpegts
added at the end of the URL:
ffmpeg -re -i /opt/flussonic/priv/bunny.mp4 -vcodec copy -vbsf h264_mp4toannexb -acodec copy -f mpegts http://localhost:80/chats/my/chat-15/mpegts
Publishing via SRT¶
You can use ffmpeg
to test the publishing:
/opt/flussonic/bin/ffmpeg -re -i PATH_TO_VIDEO -c copy -y -f mpegts 'srt://FLUSSONIC-IP:SRT_PORT?pkt_size=1316&streamid=#!::r=STREAM_NAME,m=publish'
, where:
FLUSSONIC-IP
is the Flussonic IP address.SRT_PORT
is an SRT port.STREAM_NAME
is the stream name.m=publish
is a publishing mode.
Or, you can publish a stream from any other 3d party software supporting this protocol, for example OBS Studio:
Publishing via WebRTC¶
To test a WebRTC publication, you can publish video from your webcam or use our demo app.
Protecting a publication with a password¶
Flussonic Media Server can verify a password when publishing a stream. Enter the password in the configuration file as follows:
template chats {
prefix chats;
password mypass;
input publish://;
}
stream published {
password secure;
input publish://;
}
Examples for testing:
-
To publish a password-protected RTMP stream, use the following example:
rtmp application rtmp://192.168.2.3/live
stream name mystream?password=mypass
-
To publish an HTTP MPEG-TS stream, you can enter the data as follows:
http://192.168.2.3:80/s1/mpegts?password=secure
ffmpeg -re -i video.mp4 -vcodec copy -acodec copy -f flv rtmp://192.168.2.3/live/mystream?password=mypass
ffmpeg -re -i video.mp4 -vcodec copy -bsf h264_mp4toannexb -acodec copy -f mpegts http://192.168.2.3:80/s1?password=secure
Authorization of a publishing source¶
Flussonic Media Server allows you to configure an HTTP handler that will check additional information about the publisher (that is, the source of a published stream) before accepting or rejecting the stream. Learn more at Publishing session authorization.
DVR archives and dynamic names of streams¶
You can configure the DVR archive for a publishing prefix:
template recorded {
prefix recorded;
input publish://;
dvr /storage 3d 500G;
}
In this case, the published video will be recorded, and will be available even if the publication is terminated.
When the client stops publishing the video, the stream will disappear after some time, and Flussonic Media Server will keep a very little information about it. Information about this stream will be stored in the index of the archive, and Flussonic Media Server will not lose the files on the disk.
If configured, the system of purging of the archive will delete published streams according to the schedule.
Republishing¶
To republish the streams, use push
with a template (%s
):
Danger
We do not recommend using push
over UDP in this case as it causes a collision.
template pushed {
prefix pushed;
input publish://;
push rtmp://CDN-SERVER:1936/mylive/%s;
}
With the configuration above, Flussonic republishes the pushed/mystream
stream, using the following URL: rtmp://CDN-SERVER:1936/mylive/mystream
.
Switching stream sources, using timeout¶
The rules of switching sources according to their priority and state (whether a source is available or not) apply to published sources too. This means that you can add alternative sources to a stream with a published source and use timeout for switching between sources.
If a published source is unavailable, Flussonic immediately switches by default to the next source. Alternatively, you can specify your custom timeout.
Example with multiple sources and a timeout:
stream published {
source_timeout 3;
input publish://;
input file://vod/bunny.mp4;
}
You can also specify timeout for each source individually:
stream published {
input publish:// source_timeout=3;
input file://vod/bunny.mp4 source_timeout=2;
}
Prohibiting the publishing, the publish_forbidden event in logs¶
When the source input publish://
has a lower priority than the other specified stream sources, it might mean that the publication will not actually happen. You can prevent the publication and allow it again by changing the priority of sources. This can be done during the broadcast.
If publishing is not possible, Flussonic generates the event publish_forbidden
. For example, this event occurs with the following configuration if the file bunny.mp4
exists and is successfully played:
stream published {
source_timeout 3;
input file://vod/bunny.mp4;
input publish://;
}
To allow publication, put the source of publication before the file.