Using Sample Grabber
Sample Grabber is probably the most useful filter in DirectShow.
It's a tranform filter that passes data through without changing
and can call a host application callback with each sample passing by,
this way you can see what data and when flows in different parts of your
graph and also it's the easy way to access raw media data in DirectShow
without writing your own filters.
GraphEditPlus has some special treatment for Sample Grabber both in UI
and in generated code.
By default Sample Grabber can accept virtually any data but if you
want to pass through it samples of some particular media type you can tell
Sample Grabber to only accept some selected media type. To do this
after adding this filter (it's in basic "DirectShow filters" category)
to your graph you can right click on it and select "Set media type".
The choice of preferred media type will be reflected in C++ or C# source code generated
by GraphEditPlus.
Then when the graph is build you can choose "Watch grabbed samples" from the context menu
(right click on Sample Grabber filter) and you'll see a separate window where each sample
passing through the Sample Grabber will be reflected:
You'll see a timestamp, sample's metadata like Sample Times, Media Times, flags like
is it a keyframe or not, is there a discontinuity in the sample stream or not,
actual data length and first bytes of sample's raw data. In the example above we passed
video compressed with ScreenPressor through the Sample Grabber and see that the very first
sample was a key frame 52580 bytes long and a few following samples were delta frames
(a.k.a. P-frames) each just 1 byte long with a value of 0, which means for ScreenPressor
there were no changes between those video frames.
You can learn how to use sample grabber for accessing raw video data in your own C++ or C#
application in these blog posts:
Using SampleGrabber in C++ and
Using SampleGrabber in C#.
Since version 1.5 GraphEditPlus already includes "samplegrabber.h" header file for
using Sample Grabber in C++ code (it contains some definitions from older WIndows SDK
that are missing in newer versions of Windows SDK). Generated C++ code makes use of this header.
You don't need anything extra in C# though.
|