title: How do I get a snapshot still of a video in nodejs?
body: <p>I am trying to write a nodejs server that will take a time input (possibly part of url path) and then provide a still of the video frame at that time index as a jpeg picture.</p>
  
  <p>I can do this easily in plain Javascript, but I cant see a way to do this in nodejs. I know I will probably need to use a canvas plugin like node-canvas to do the snapshot.</p>
  
  <p>Any ideas welcome.</p>
  
  <p>The following is how I do it in Javascript at the moment:</p>
  
  <p>myjavascript.js</p>
  
  <pre><code>function capture(video, scaleFactor) {
      if(scaleFactor == null){
          scaleFactor = 1;
      }
      var w = video.videoWidth * scaleFactor;
      var h = video.videoHeight * scaleFactor;
      stdout("&lt;br/&gt; w: "+ w+ "&lt;br/&gt; h: "+ h);
      var canvas = document.createElement('canvas');
          canvas.width  = w;
          canvas.height = h;
      var ctx = canvas.getContext('2d');
          ctx.drawImage(video, 0, 0, w, h);
      return canvas;
  }
  
  function shoot(){
   var video  = document.getElementById("videoTag");
   var output = document.getElementById("output");
   var canvas = capture(video, 1);
   output.innerHTML = '';
   output.appendChild(canvas);
  }
  </code></pre>
  
  <p>index.html</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;video snap&lt;/title&gt;   
      &lt;script type="text/javascript" src="myjavascript.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div id="video_container" &gt;
          &lt;video id="videoTag" width="640" height="360" autobuffer="" controls="true"&gt;
              &lt;source src="frozenplanet.mp4" type="video/mp4"&gt;
              &lt;source src="frozenplanet.ogv" type="video/ogg"&gt;
          &lt;/video&gt;
  &lt;/div&gt;
  
  &lt;div id="output"&gt;&lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>