main.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:2k
- unit main;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, DSUtil, StdCtrls, DSPack, DirectShow9, Menus, ExtCtrls;
- type
- TVideoForm = class(TForm)
- FilterGraph: TFilterGraph;
- MainMenu1: TMainMenu;
- Devices: TMenuItem;
- OpenDialog: TOpenDialog;
- Filter: TFilter;
- ASFWriter: TASFWriter;
- VideoWindow: TVideoWindow;
- procedure FormCreate(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- private
- { D閏larations priv閑s }
- public
- { D閏larations publiques }
- procedure OnSelectDevice(sender: TObject);
- end;
- var
- VideoForm: TVideoForm;
- SysDev: TSysDevEnum;
- implementation
- uses Math;
- {$R *.dfm}
- procedure TVideoForm.FormCreate(Sender: TObject);
- var
- i: integer;
- Device: TMenuItem;
- begin
- SysDev:= TSysDevEnum.Create(CLSID_VideoInputDeviceCategory);
- if SysDev.CountFilters > 0 then
- for i := 0 to SysDev.CountFilters - 1 do
- begin
- Device := TMenuItem.Create(Devices);
- Device.Caption := SysDev.Filters[i].FriendlyName;
- Device.Tag := i;
- Device.OnClick := OnSelectDevice;
- Devices.Add(Device);
- end;
- end;
- procedure TVideoForm.OnSelectDevice(sender: TObject);
- begin
- FilterGraph.ClearGraph;
- FilterGraph.Active := false;
- Filter.BaseFilter.Moniker := SysDev.GetMoniker(TMenuItem(Sender).tag);
- FilterGraph.Active := true;
- with FilterGraph as ICaptureGraphBuilder2 do
- begin
- CheckDSError(RenderStream(@PIN_CATEGORY_CAPTURE , nil, Filter as IBaseFilter, nil, ASFWriter as IbaseFilter));
- CheckDSError(RenderStream(@PIN_CATEGORY_PREVIEW , nil, Filter as IBaseFilter, nil, VideoWindow as IbaseFilter));
- end;
- FilterGraph.Play;
- end;
- procedure TVideoForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- SysDev.Free;
- FilterGraph.ClearGraph;
- FilterGraph.Active := false;
- end;
- end.