部分代码:
procedure TMainForm.StartButtonClick(Sender: TObject);
var
multiplexer: IBaseFilter;
Writer: IFileSinkFilter;
PinList: TPinList;
i: integer;
begin
// Activate the filter graph, at this stage the source filters are added to the graph
CaptureGraph.Active := true;
// configure output Audio media type + source
if AudioSourceFilter.FilterGraph <> nil then
begin
PinList := TPinList.Create(AudioSourceFilter as IBaseFilter);
i := 0;
while i < PinList.Countdo
if PinList.PinInfo.dir = PINDIR_OUTPUT then
begin
if AudioFormats.ItemIndex <> -1 then
with (PinList.Items as IAMStreamConfig)do
SetFormat(AudioMediaTypes.Items[AudioFormats.ItemIndex].AMMediaType^);
PinList.Delete(i);
end else
inc(i);
if InputLines.ItemIndex <> -1 then
with (PinList.Items[InputLines.ItemIndex] as IAMAudioInputMixer)do
put_Enable(true);
PinList.Free;
end;
// configure output Video media type
if VideoSourceFilter.FilterGraph <> nil then
begin
PinList := TPinList.Create(VideoSourceFilter as IBaseFilter);
if VideoFormats.ItemIndex <> -1 then
// with (PinList[1] as Iamoviesetup)do
with (PinList.Items[InputLines.ItemIndex] as IAMStreamConfig)do
SetFormat(VideoMediaTypes.Items[VideoFormats.ItemIndex].AMMediaType^);
PinList.Free;
end;
// now render streams
with CaptureGraph as IcaptureGraphBuilder2do
begin
// set the output filename MEDIASUBTYPE_ASF
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,
VCompFilter as IBaseFilter , 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
if AudioSourceFilter.FilterGraph <> nil then
begin
RenderStream(nil, nil, AudioSourceFilter as IBaseFilter,
nil, multiplexer as IBaseFilter);
end;
end;
CaptureGraph.Play;
StopButton.Enabled := true;
StartButton.Enabled := false;
AudioFormats.Enabled := false;
AudioCapFilters.Enabled := false;
VideoFormats.Enabled := false;
VideoCapFilters.Enabled := false;
Timer.Enabled := true;
end;