Search code examples
windowsvideodirectshowwebcam-capture

ISampleGrabberCB::SampleCB timestamp


I am trying to capture video stream from web camera by using DirectShow and ISampleGrabber interface. I would like to get timestamp for every grabbed frame. But SampleTime parameter in SampleCB(double SampleTime, IMediaSample *pSample) method is always zero.

Why it can be zero? Does this value depend on the camera driver implementation or something else? Are there any other ways to get timestamp for the grabbed frame?


Solution

  • Time stamp might be zero if you capture from preview pin, or preview leg derived from camera through Smart Tee Filter. The time stamp is not zero, the frames are simply not time stamped and Sample Grabber filter offers no way to distinguish between the two scenarios.

    You can easily verify time stamping using GraphStudioNext's Analyzer Filter, or using DumpMediaSamples.

    In your application you are first of all interested in exact topology of your graph, what filters are connected upstream to Sample Grabber. Most likely you need to update your code to eliminate use of previewing.