title: How to send MPEGTS streams over UDP
body: <p>I am developing a realtime video-streaming system which is composed basically by a server and several clients.</p>
  
  <p>For now, let's ignore how packets are forwarded among the server and the clients, let's focus just on <strong>how the server can send a MPEGTS stream over UDP packets</strong>.</p>
  
  <p>The stream is encoded in MPEGTS format.</p>
  
  <p>What I'm trying to do is reading some packets (the main question is "how many?") and encapsulating them in UDP packets. The destination (a client) reads these UDP packets and then forward them to VLC, which is able to play MPEGTS network streams by reading UDP packets.</p>
  
  <p><strong>If I send only video packets, everything works fine</strong>, instead if I try to encapsulate in the same UDP packet, both some video packets and some audio packets, VLC is not able to decode and play the stream.
  I read somewhere that each UDP packet should contain 7 TS packets, but unfortunately even if I comply with this rule, VLC doesn't decode the stream correctly.</p>
  
  <p>Here is a sample code of my program: <a href="http://pastebin.com/evMi6FkY" rel="noreferrer">http://pastebin.com/evMi6FkY</a></p>
  
  <p><strong>How should I encapsulate MPEGTS packets in UDP packets?</strong></p>
  
  <p>Thanks!</p>