title: Converting raw frames into webm live stream
body: <p>I have an ASP.NET application with the following set up:</p>
  
  <ol>
  <li>A camera that captures raw RGB frames at a resolution 656x492     </li>
  <li>These frames are processed in my C# code (with some simple image
  processing)</li>
  <li>The raw image is stored in a byte array (as well as wrapped in a Bitmap  container)</li>
  <li><strong><em>MISSING MAGIC: Convert raw image buffer to WebM stream</em></strong></li>
  <li>On the other end I have a function <code>HttpResponseMessage</code> function that hooks up a WebM stream with a <code>PushStreamContent</code> function (inspired by this <a href="http://www.strathweb.com/2013/01/asynchronously-streaming-video-with-asp-net-web-api/" rel="nofollow">blog post</a>). This function pushes chunks of a video file to the website.</li>
  <li>A Website that plays back the video. </li>
  </ol>
  
  <p>I am struggling to figure out how to implement <strong>point 4</strong>. Right now I can only stream video files. But I would like to encode my raw buffer into a WebM container and stream that to my website. The central piece of code of <strong>point5</strong> looks as follows: </p>
  
  <pre><code>while (length &gt; 0 &amp;&amp; bytesRead &gt; 0)
  {
      bytesRead = video.Read(buffer, 0, Math.Min(length, buffer.Length));
      await outputStream.WriteAsync(buffer, 0, bytesRead);
      length -= bytesRead;
  }
  </code></pre>
  
  <p>Basically I would like to replace the <code>video.Read</code> function by somehow encoding my raw frames into a WebM format on the fly and storing them in <code>buffer</code>, so they can be pushed to the website as a live stream. Is there a straight forward way to do this? It's fine if some frames get dropped. </p>
  
  <p>If there is an entirely different approach that is better then I am of course also open for suggestions. </p>