title: Motion jpeg in html5 canvas
body: <p>I'm trying to wrap motion jpeg (mjpeg) stream (from webcam) into html5 canvas. I know Safari and Chrome have native support for mjpeg so that I can put it into <code>img</code> to make it work. The reason I want to wrap it in canvas is that I want to do some post processing on it.</p>
  
  <p>I know i can use <code>drawImage</code> to load an image (and mjpeg):</p>
  
  <pre><code>&lt;html&gt;
    &lt;body&gt;
      &lt;canvas id='test_canvas' width='640px' height='480px' style='border:1px solid #d3d3d3'&gt;
      &lt;/canvas&gt;
      &lt;script language="JavaScript"&gt;
        var ctx = document.getElementById('test_canvas').getContext('2d');
        var img = new Image();
        img.onload = function() {
          ctx.drawImage(img, 0, 0);
        };
        var theDate = new Date();
        img.src = "http://some.video.stream.edu/axis-cgi/mjpg/video.cgi?";
      &lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>However, it load mjpeg as an image so only display the first frame. Put <code>ctx.drawImage(img, 0, 0)</code> into a <code>while (true)</code> loop also not help (not surprisingly).</p>
  
  <p>I think there should be some tricks to make it work, still googling around, just not sure which direction is more promising. It is OK to be only supported by some reasonably modern browsers.</p>