Working with UDP multicast MPEG-TS streams on Linux

A most common task for all OTT and IPTV video services is, of course, to encode a group of TV channels. And the most common way you will be receiving channels is MPEG-TS streams via multicast UDP. In this article we have explained some popular tips and tricks for working with UDP multicast MPEG-TS streams on Ubuntu and CentOS. We assume you have a linux server or a workstation with a root (superuser) access and a bunch of multicast streams available in your network.

Checking a multicast UDP stream

Suppose you know incoming UDP MPEG-TS multicast host and port:

udp://233.0.41.102:20000

In this URL 233.0.41.102 is called IP address (or host) and 20000 is port. We will use these later as an example for configuration settings.

Using tcpdump

Let’s make sure we are actually receiving a stream using [tcpdump][1]. You must be root to run tcpdump. Execute the following command:

> tcpdump -c 10 dst host 233.0.41.102 and port 20000 and multicast

This command tells to capture 10 multicast UDP packets sent to host 233.0.41.102 and port 20000. If the stream is running, you shall get something like:

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
15:20:58.818832 IP 43.232.net.50000 > 233.0.41.102.20000: UDP, length 1316
15:20:58.824080 IP 43.232.net.50000 > 233.0.41.102.20000: UDP, length 1316
15:20:58.829467 IP 43.232.net.50000 > 233.0.41.102.20000: UDP, length 1316
15:20:58.835816 IP 43.232.net.50000 > 233.0.41.102.20000: UDP, length 1316
15:20:58.841053 IP 43.232.net.50000 > 233.0.41.102.20000: UDP, length 1316
15:20:58.846617 IP 43.232.net.50000 > 233.0.41.102.20000: UDP, length 1316
15:20:58.852052 IP 43.232.net.50000 > 233.0.41.102.20000: UDP, length 1316
15:20:58.857893 IP 43.232.net.50000 > 233.0.41.102.20000: UDP, length 1316
15:20:58.863787 IP 43.232.net.50000 > 233.0.41.102.20000: UDP, length 1316
15:20:58.869017 IP 43.232.net.50000 > 233.0.41.102.20000: UDP, length 1316
10 packets captured
70 packets received by filter
4 packets dropped by kernel

If you don’t see output and tcpdump seems to freeze, you are not receiving multicast packets. Press Ctrl-C to abort tcpdump and refer to the next section on firewall settings.

Using netstat

An alternative way to check multicast stream is by using [netstat][2] tool. You also need to be root to use it.

> netstat -a -u -n | grep 233.0.41.102:20000

If multicast stream is running, you will see:

udp        0      0 233.0.41.102:20000      0.0.0.0:*
(this line may appear twice or more times)

If previous command emits nothing, you are not receiving multicast packets. Refer to the next section on firewall settings.

Firewall and multicast issues with multicast

Very often multicast streams are block