使用direct show 实时采集图像时,如何抓拍一段录像保存在硬盘上(100分)

J

jzg2727

Unregistered / Unconfirmed
GUEST, unregistred user!
使用direct show 实时采集图像时,如何抓拍一段录像保存在硬盘上
点击button按钮可以录3,5秒钟,保存成avi或者其他的格式
 
为什么不用VFW或相关控件?要么MediaServer可以帮你解决一切视频会议的相关问题[:)]
 
连接一个数据保存过滤器
 
DIRECT DRAW, DIRECT SHOW这是什么控件呀.在那里有下载?
 
好像有那么一个 filter, 有两个输出 pin
然后将一个输出 pin 接到 file render 就可以了
我记得在 sdk 的帮助里看到过,不太清楚了,很久没玩这个东东了

 
使用 dspack2.0

unit main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DSPack, DSUtil, DirectShow, ComCtrls, ExtCtrls;

type
TMainForm = class(TForm)
CaptureGraph: TFilterGraph;
VideoWindow: TVideoWindow;
VideoCapFilters: TListBox;
VideoSourceFilter: TFilter;
StartButton: TButton;
CapFileButton: TButton;
SaveDialog: TSaveDialog;
StopButton: TButton;
VideoFormats: TListBox;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure VideoCapFiltersClick(Sender: TObject);
procedure StartButtonClick(Sender: TObject);
procedure CapFileButtonClick(Sender: TObject);
procedure StopButtonClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;


var
MainForm: TMainForm;
CapEnum: TSysDevEnum;
VideoMediaTypes: TEnumMediaType;
CapFile: WideString = 'c:/capture.avi';
implementation

{$R *.dfm}

{ TMainForm }

procedure TMainForm.FormCreate(Sender: TObject);
begin

CapEnum := TSysDevEnum.Create(CLSID_VideoInputDeviceCategory);
VideoCapFilters.Items.Add(CapEnum.Filters[0].FriendlyName);
CapEnum.SelectGUIDCategory(CLSID_AudioInputDeviceCategory);
VideoMediaTypes := TEnumMediaType.Create;
end;


procedure TMainForm.FormDestroy(Sender: TObject);
begin

CapEnum.Free;
VideoMediaTypes.Free;
end;


// Select the video Source
procedure TMainForm.VideoCapFiltersClick(Sender: TObject);
var
PinList: TPinList;
begin

CapEnum.SelectGUIDCategory(CLSID_VideoInputDeviceCategory);
begin

VideoSourceFilter.BaseFilter.Moniker := CapEnum.GetMoniker(0);
VideoSourceFilter.FilterGraph := CaptureGraph;
CaptureGraph.Active := true;
PinList := TPinList.Create(VideoSourceFilter as IBaseFilter);
VideoFormats.Clear;
VideoMediaTypes.Assign(PinList.First);
VideoFormats.Items.Add(VideoMediaTypes.MediaDescription[0]);
CaptureGraph.Active := false;
PinList.Free;
StartButton.Enabled := true;
end;

end;


// Start Capture
procedure TMainForm.StartButtonClick(Sender: TObject);
var
multiplexer: IBaseFilter;
Writer: IFileSinkFilter;
PinList: TPinList;
begin

VideoCapFiltersClick(Sender);
// Activate the filter graph, at this stage the source filters are added to the graph
CaptureGraph.Active := true;
// configure output Video media type
if VideoSourceFilter.FilterGraph <> nil then

begin

PinList := TPinList.Create(VideoSourceFilter as IBaseFilter);
if VideoFormats.ItemIndex <> -1 then

with (PinList.First as IAMStreamConfig)do

SetFormat(VideoMediaTypes.Items[VideoFormats.ItemIndex].AMMediaType^);
PinList.Free;
end;

// now render streams
with CaptureGraph as IcaptureGraphBuilder2do

begin

// set the output filename
SetOutputFileName(MEDIASUBTYPE_Avi, PWideChar(CapFile), multiplexer, Writer);
// Connect Video preview (VideoWindow)
if VideoSourceFilter.BaseFilter.DataLength > 0 then

RenderStream(@PIN_CATEGORY_PREVIEW, nil, VideoSourceFilter as IBaseFilter,
nil , VideoWindow as IBaseFilter);
// Connect Video capture streams
if VideoSourceFilter.FilterGraph <> nil then

RenderStream(@PIN_CATEGORY_CAPTURE, nil, VideoSourceFilter as IBaseFilter,
nil, multiplexer as IBaseFilter);
// Connect Audio capture streams
end;

CaptureGraph.Play;
StopButton.Enabled := true;
StartButton.Enabled := false;
VideoFormats.Enabled := false;
VideoCapFilters.Enabled := false;
end;


// Select the Ouput file
procedure TMainForm.CapFileButtonClick(Sender: TObject);
begin

if SaveDialog.Execute then

CapFile := SaveDialog.FileName;
end;


// Stop Capture
procedure TMainForm.StopButtonClick(Sender: TObject);
begin

StopButton.Enabled := false;
StartButton.Enabled := true;
CaptureGraph.Stop;
CaptureGraph.Active := False;
VideoFormats.Enabled := true;
VideoCapFilters.Enabled := true;
end;



end.
 
顶部