How To: Dump DirectShow media samples

Given a DirectShow filter graph, what media samples are being sent through particular graph point? DumpMediaSamples utility gives a fast answer to this question. It prints out connection media type details (with details of VIDEOINFOHEADER, VIDEOINFOHEADER2 and WAVEFORMATEX structures corresponding to FORMAT_VideoInfo, FORMAT_VideoInfo2 and FORMAT_WaveFormatEx format types) and IMediaSample details obtained through AM_SAMPLE2_PROPERTIES structure. First of all, it is necessary to create a graph of interest using GraphEdit utility. At the point of interest it is necessary to insert [an uninitialized] Sample Grabber Filter with the filter name “SampleGrabber” (this is the default name but if you add second filter which will be given a different name and remove first filter then, the utility would fail). The graph may look like this:

Save the graph into a file and start utility providing filter graph path as a command line argument. The utility will load the graph, locate the inserted Sample Grabber Filter and run the graph. Any sample passing through will be printed:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>DumpMediaSamples Test.grf
Media Type:

majortype {73646976-0000-0010-8000-00AA00389B71}, subtype {44495658-0000-0010-8000-00AA00389B71}, pUnk 0x00000000
bFixedSizeSamples 1, bTemporalCompression 0, lSampleSize 23443
formattype {05589F80-C356-11CE-BF01-00AA0055595A}, cbFormat 88, pbFormat 0x0017a7b0
pbFormat as VIDEOINFOHEADER:
  rcSource { 0, 0, 0, 0 ), rcTarget { 0, 0, 0, 0 }
  dwBitRate 372125, dwBitErrorRate 0, AvgTimePerFrame 400,000.00
  bmiHeader.biSize 40, bmiHeader.biWidth 400, bmiHeader.biHeight 320, bmiHeader.biPlanes 1, bmiHeader.biBitCount 16, bmiHeader.biCom
pression XVID
  bmiHeader.biSizeImage 768000, bmiHeader.biXPelsPerMeter 0, bmiHeader.biYPelsPerMeter 0, bmiHeader.biClrUsed 0, bmiHeader.biClrImpo
rtant 0

Media Samples:

fSampleTime 0.000, .dwTypeSpecificFlags 0x00000000, .dwSampleFlags 0x00000115, .tStart 000000000, .tStop 000400000, .dwStreamId 0
.cbBuffer 23443, .lActual 15621, pbBuffer 00 00 01 B0 F5 00 00 01 B5 09 00 00 01 00 00 00 01 20 08 86 84 00 67 0C 32 10 A0 51 8F 00 00 01 B2 44 69 76 58 35 30 33 62 31 33 39 33 70 00 00

fSampleTime 0.040, .dwTypeSpecificFlags 0x00000000, .dwSampleFlags 0x00000110, .tStart 000400000, .tStop 000800000, .dwStreamId 0
.cbBuffer 23443, .lActual 1, pbBuffer 7F

fSampleTime 0.080, .dwTypeSpecificFlags 0x00000000, .dwSampleFlags 0x00000110, .tStart 000800000, .tStop 001200000, .dwStreamId 0
.cbBuffer 23443, .lActual 1, pbBuffer 7F

A pre-built binary (Win32) and reference Visual C++ project source code (will require additional headers to compile) are available from SVN.

2 Replies to “How To: Dump DirectShow media samples”

Leave a Reply