Stream over RTP¶
This page explains how VLC Media Player can be used to stream a file locally over RTP. Streaming locally means that the streaming device and all the receiving device(s) should be connected to the same router for the streaming to work.
To stream over RTP, we will use the rtp
module in the sout
chain. Note that unlike when streaming over HTTP or UDP, we cannot use the std{access=
format for streaming over RTP.
For VLC, streaming over RTP works by pushing the content to the target IP, which can be:
A unicast address (when streaming to a specific device), or
A multicast address (when streaming to multiple devices in the local network).
The default port suggested for RTP streaming is 5004
, however you can pick any of the free ports as per your choice. For this example we will stream on port number 5010
.
Unicast Streaming over RTP¶
Let us assume that the IP addresses of the server and client are:
Streaming device: 192.168.0.101
Receiving device: 192.168.0.102
Sending the Unicast Stream¶
To push the stream, run the following code on the streaming device:
$ vlc sample.mp4 --sout="#rtp{mux=ts, dst=192.168.0.102, port=5010}"
Notice that the IP address in dst
is the IP address of the receiving device.
Receiving the Unicast Stream¶
To receive the stream, run the following code on the receiving device:
$ vlc rtp://:5010
Alternatively, you could write the IP address of the client device itself which will accomplish the same thing:
$ vlc rtp://192.168.0.101:5010
Diagramatically, this is a simplified representation of how the network would look like when unicast streaming over rtp
:
Multicast Streaming over RTP¶
Streaming to the multicast IP address essentially means that the stream will the pushed to all the devices in the local network. So any device that wishes to receive the stream can connect to the relevant port and start receiving.
Continuing with the example above, let’s assume that the IP address of the streaming device is the same (that is, 192.168.0.101
), and that the multicast IP address is 239.255.255.250
.
Sending the Multicast Stream¶
To push the stream, run the following code in the streaming device:
$ vlc sample.mp4 --sout="#rtp{mux=ts, dst=239.255.255.250, port=5010}"
Receiving the Multicast Stream¶
To receive the stream, run the following code on the receiving devices:
$ vlc rtp://239.255.255.250:5010
Note that for receiving the multicast stream, it is important to specify the multicast IP address. Diagramatically, following is how the network might look like in this scenario:
Using Session Protocols¶
You can use SAP announcements while streaming over RTP. This will help to “discover” streams on the receiving devices and seamlessly connect without having to execute any code. Refer to Using SAP while Streaming to understand how to use SAP announcements.
You can also use RTSP as the session management protocol. In this, the streaming will still happen over RTP but the session parameters (like IP address and the port number) will be negotiated by the RTSP protocol. Hence, the sender will not have to manually mention the IP address(es) of the receivers. Refer to Stream using RTSP to understand how to use RTSP for streaming.
Taking it a step further, it is possible to use both SAP and RTSP simultaneously. This gives the client the choice to either connect through the SAP discovery option, or by using the RTSP link.