title: Efficiently grabbing pixels from video
body: <p>I am looking for an effective way to grab image data off video files. I am currently testing <code>FilgraphManagerClass.GetCurrentImage()</code> from the <code>Interop.QuartzTypeLib</code> library. This does what I need but is painfully slow. I need to process all frames of each video. What better options do I have?</p>
  
  <p>Requirements</p>
  
  <ul>
  <li>Must be frame accurate. &lt;-- Very important!</li>
  <li>Gives me access to the decoded pixel buffer (array of <code>int</code> or <code>byte[]</code>), ideally RGB24 or RGB32.</li>
  <li>The buffer can be grabbed in realtime or faster. I do not need to display the video, I only need to analyze the pixels.</li>
  <li>Handle mp4 files (h264/aac). I can rewrap or frame serve via AviSynth if needed but no retranscoding can be involved.</li>
  </ul>
  
  <p>Any suggestions would be welcome.</p>
  
  <p>Some code as requested:</p>
  
  <pre><code>FilgraphManagerClass graphClass = new FilgraphManagerClass();
  graphClass.RenderFile(@"C:\tmp\tmp.avs");
  
  int sz = (graphClass.Width * graphClass.Height + 10) * 4;    
  int[] buffer = new int[sz - 1];
  </code></pre>
  
  <p>I am then stepping through each frame. I have something like this in the loop:</p>
  
  <pre><code>graphClass.GetCurrentImage(ref sz, out buffer[0]);
  //DoStuff(buffer);
  graphClass.CurrentPosition += graphClass.AvgTimePerFrame;
  </code></pre>