to:GGCAT
我的程序原理如下:
CoCreateInstance(CLSID_FilterGraph,NIL,CLSCTX_INPROC,IID_IGraphBuilder,dsGraphBuilder;
dsGraphBuilder.QueryInterface(IID_IMediaControl,dsMediaControl);
dsGraphBuilder.QueryInterface(IID_IMediaSeeking,dsMediaSeeking;
dsGraphBuilder.QueryInterface(IID_IBasicAudio,dsBasicAudio);
dsGraphBuilder.QueryInterface(IID_IBasicVideo,dsBasicVideo);
dsGraphBuilder.QueryInterface(IID_IVideoWindow,dsVideoWindow);
//
CoCreateInstance(CLSID_FilterGraph,NIL,CLSCTX_INPROC_SERVER,IID_IBaseFilter,dsBaseFilter);
//
dsBaseFilter.QueryInterface(IID_ISampleGrabber, dsSampleGrabber);
ZeroMemory(@mt,sizeof(TAM_MEDIA_TYPE));
mt.majortype:= MEDIATYPE_Video;
mt.subtype:= MEDIASUBTYPE_RGB24;
mt.formattype:= FORMAT_VideoInfo;
dsSampleGrabber.SetMediaType(mt);
dsGraphBuilder.AddFilter(dsBaseFilter,'Grabber');
If dsGraphBuilder.RenderFile(@UnicodeFileName,nil) = S_OK then
begin
If Assigned(dsSampleGrabber) then
begin
dsSampleGrabber.SetBufferSamples(TRUE);// 设立样例缓冲区
dsSampleGrabber.SetOneShot(TRUE);// 设立单步模式。
end;
但是(按照DirectShow中的说明)创建IID_IBaseFilter出错(其他正确,可以正常回放MPEG文件),
请教什么原因。
另外,如何保存为BMP文件:
procedure TMainForm.GrabButtonClick(Sender: TObject);
var
hBitmap : THANDLE;
MediaType: TAM_MEDIA_TYPE
BITMAPINFO: TBitmapInfo;
pVideoHeader: ^TVIDEOINFOHEADER;
buf : Pointer;
begin
dsSampleGrabber.GetConnectedMediaType(MediaType);
// 获取一个指向视频头的指针。
pVideoHeader:= MediaType.pbFormat;
// 视频头包含位图信息。// 将它拷贝到BITMAPINFO结构。
ZeroMemory(@BitmapInfo, sizeof(BitmapInfo));
CopyMemory(@BitmapInfo.bmiHeader, @(pVideoHeader.bmiHeader), sizeof(BITMAPINFOHEADER));
// 从位图头创建一个DIB并取得指向缓冲区的指针。
hBitmap:= CreateDIBSection(0, TBITMAPINFO(BitmapInfo), DIB_RGB_COLORS, buf, NULL, 0);
// 将图象拷贝到缓冲区。
dsSampleGrabber.GetCurrentBuffer(0,buf);
// ????????????SaveToFile('c:/test.bmp');???????????????
end;