title: Video streaming with HTML 5 via node.js
body: <p>I'm trying to set up a web server that will support streaming video to an HTML5 video tag using node.js.  Here's my code so far:</p>
  
  <pre><code>var range = request.headers.range;
  var total = file.length;
  
  var parts = range.replace(/bytes=/, "").split("-");
  var partialstart = parts[0];
  var partialend = parts[1];
  
  var start = parseInt(partialstart, 10);
  var end = partialend ? parseInt(partialend, 10) : total-1;
  
  var chunksize = (end-start)+1;
  
  response.writeHead(206, { "Content-Range": "bytes " + start + "-" + end + "/" + total, "Accept-Ranges": "bytes", "Content-Length": chunksize, "Content-Type": type });
  response.end(file);
  </code></pre>
  
  <p>Where "request" represents the http request, type is either "application/ogg" or "video/ogg" (I've tried both) and "file" is the .ogv file that's been read from the file system.  Here are the response headers:</p>
  
  <pre><code>Content-Range   bytes 0-14270463/14270464
  Accept-Ranges   bytes
  Content-Length   14270464
  Connection     keep-alive
  Content-Type     video/ogg
  </code></pre>
  
  <p>I've examined the response headers and this code appears to be working fine, but there are a couple of problems:</p>
  
  <ol>
  <li>The video appears to load very slowly for being on a local network.  From what I can tell examining the response using firebug, the file appears to be streamed in at about 150 kb/sec.</li>
  <li>The video doesn't play at all.  Even if I wait for the whole thing to load, the HTML 5 video tag just shows a big "x" instead of a movie in firefox.</li>
  </ol>
  
  <p>Does anyone have any ideas as to what I can do to get video streaming working via node.js?</p>
  
  <p>Thanks!<br>
  Chris</p>