title: Play MPEG-2 TS using MseStreamSource
body: <p>I need to display a live video stream in a UWP application.</p>
  
  <p>The video stream comes from a GoPro. It is transported by UDP messages. It is a MPEG-2 TS stream. I can play it successfully using FFPlay with the following command line :</p>
  
  <pre><code>ffplay -fflags nobuffer -f:v mpegts udp://:8554
  </code></pre>
  
  <p>I would like to play it with MediaPlayerElement without using a third party library.</p>
  
  <p>According to the following page :
  <a href="https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/supported-codecs" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/windows/uwp/audio-video-camera/supported-codecs</a>
  UWP should be able to play it. (I installed the "Microsoft DVD" application in the Windows Store).</p>
  
  <p>I receive the MPEG-2 TS stream with a UdpClient. It works well.
  I receive in each UdpReceiveResult a 12 bytes header, followed by 4, 5, 6, or 7 MPEGTS packets (each packet is 188 bytes, beginning with 0x47).</p>
  
  <p>I created a MseStreamSource :</p>
  
  <pre><code>_mseStreamSource = new MseStreamSource();
  _mseStreamSource.Opened += (_, __) =&gt;
  {
      _mseSourceBuffer = _mseStreamSource.AddSourceBuffer("video/mp2t");
      _mseSourceBuffer.Mode = MseAppendMode.Sequence;
  };
  _mediaPlayerElement.MediaSource = MediaSource.CreateFromMseStreamSource(_mseStreamSource);
  </code></pre>
  
  <p>This is how I send the messages to the MseStreamSource :</p>
  
  <pre><code>    UdpReceiveResult receiveResult = await _udpClient.ReceiveAsync();
      byte[] bytes = receiveResult.Buffer;
      mseSourceBuffer.AppendBuffer(bytes.AsBuffer());
  </code></pre>
  
  <p>The MediaPlayerElement displays the message "video not supported or incorrect file name". (not sure of the message, my Windows is in French).</p>
  
  <p>Is it a good idea to use the MseAppendMode.Sequence mode ?
  What should I pass to the AppendBuffer method ? The raw udp message including the 12 bytes header or each MPEGTS 188 bytes packet ?</p>