4

I have written a program where i get udp packet from a multicast address. Now i need to extract the mpegts from this packet. I am able to take the payload of the udp packet. Can some one help me to extract the mpeg header from the udp packet.

iwant2learn
  • 163
  • 3
  • 8

1 Answers1

4

MpegTS is typically transported over UDP with RTP. Skip the RTP header. The rest (188*7 bytes) is the payload, 7 TS packets. Each packet should start with 0x47.

Update:

There are multiple packetizing layers each wrapping/chunking the sequence. The upper layers are quite nice, the bottom one (elementary stream) is codec dependent and quite messy.

MPEG TS - MPEG PES - MPEG ES

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
  • Thanks u for the information...Is there any structure where i can reuse. I do not have an RTP header with in the packet. so i have only the mpeg packet. How do i traverse the header because i am not storing it in any file. I capture the packet from a multicast address and i have to do the processing. – iwant2learn Jul 12 '11 at 09:54
  • what kind of processing is this? you could use ffmpeg for recoding. – Karoly Horvath Jul 12 '11 at 10:11
  • its a multicast routing program, where i need to process the udp packets arriving at two different ports of a multicast address. I have to perform a switching operation between the two stream arriving at the two ports. – iwant2learn Jul 13 '11 at 08:23
  • I guess the codecs for the two stream are the same, right? still, you might have to do a lot of transformation... reference clocks going to differ, maybe program tables (PAT & MPT) as well. and you have to switch on reference frames. that's sounds quite complex. You probably have to do recoding, but I'm not quite sure. Check gstreamer. Let me know if you managed to do this! – Karoly Horvath Jul 13 '11 at 08:41
  • Yes the two stream have the same codec and in fact both are same stream but differently watermark. Can u suggest me more on how to update the PAT and PMT tables. Thanks for the advice. Will surely update if i am able to do the operation. – iwant2learn Jul 13 '11 at 12:46
  • You only have to update those if they use different PIDs for transferring program info, audio and video streams. If it is the same you don't have to worry about that. – Karoly Horvath Jul 13 '11 at 12:59
  • ok... i have the same PID for both the streams. I have metadata embedded with in the streams, giving details of what the watermark is, and that a switch is possible and the position where to switch. With these information do u think that i will be able to switch between the two streams. Thanks in advance – iwant2learn Jul 13 '11 at 13:05
  • Ok, you still have to generate a brand new reference clock because the reference clocks for those two streams will differ. Knowing where to switch (end of frame seq, start of next one) will be a *huge help*. But you probably still have to do a couple of more things like synchronize the continuity counters for each PID.. If you want constant bitrate you might have to add or remove filling(PID 8191) packets. I think it's possible of doing this, but don't really know... I'm fairly new to these technologies. If it doesn't work you're going to have a very hard time figuring out what went wrong. – Karoly Horvath Jul 13 '11 at 13:55
  • Create a separate question for this, maybe also linking to this discussion. I'm very interested in this topic. – Karoly Horvath Jul 13 '11 at 13:57
  • Thanks a lot for your input... I surely will create a new thread for this. :) – iwant2learn Jul 13 '11 at 17:15