先凑合看着,正准备写复合流分割的笔记呢.
procedure TMainForm.RewriteVideo(const SourceFileName,
DestFileName: string);
var
Builder: ICaptureGraphBuilder2;
Graph: IGraphBuilder;
FileSource: IBaseFilter;
Mux: IBaseFilter;
FileWriter: IFileSinkFilter;
MediaControl: IMediaControl;
MediaEvent: IMediaEvent;
PinEnum: IEnumPins;
Pin: IPin;
PinInfo: TPin_Info;
MediaType: TAM_Media_Type;
EVCode: Integer;
FileName: array [0..255] of WideChar;
R: Integer;
Res: HResult;
begin
CoCreateInstance(CLSID_CaptureGraphBuilder2, nil, CLSCTX_INPROC,
IID_ICaptureGraphBuilder2, Builder);
StringToWideChar(DestFileName, FileName, 256);
Builder.SetOutputFileName(MEDIASUBTYPE_Avi, FileName, Mux, FileWriter);
Builder.GetFiltergraph(Graph);
AddToROT(Graph, R);
StringToWideChar(SourceFileName, FileName, 256);
Graph.RenderFile(FileName, nil);
Mux.EnumPins(PinEnum);
Res:=PinEnum.Next(1, Pin, nil);
while Res=S_OKdo
begin
Pin.QueryPinInfo(PinInfo);
if PinInfo.dir=PINDIR_INPUT then
begin
Pin.ConnectionMediaType(MediaType);
if not SameGUID(MediaType.majortype, MediaType_Video) then
Pin.Disconnect
end;
Res:=PinEnum.Next(1, Pin, nil)
end;
PinEnum:=nil;
Graph.QueryInterface(IID_IMediaControl, MediaControl);
Graph.QueryInterface(IID_IMediaEvent, MediaEvent);
MediaControl.Run;
MediaEvent.WaitForCompletion(INFINITE, EVCode);
MediaControl.Stop;
RemoveFromROT(R);
MediaEvent:=nil;
MediaControl:=nil;
FileWriter:=nil;
Mux:=nil;
FileSource:=nil;
Graph:=nil;
Builder:=nil
end;