L
lxmzm
Unregistered / Unconfirmed
GUEST, unregistred user!
LeeChange:
你好!
在论坛上,看到你提供的方法!我试了一下,从DAT文件抽取的AVI文件,用系统播放机无法播放,在抽取音频文件后,也无法播放,这是什么原因呢?
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TMainForm = class(TForm)
SourceEdit: TEdit;
DestEdit: TEdit;
SourceSpeedButton: TSpeedButton;
DestSpeedButton: TSpeedButton;
ActionButton: TButton;
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
procedure SourceSpeedButtonClick(Sender: TObject);
procedure DestSpeedButtonClick(Sender: TObject);
procedure ActionButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
function SameGUID(const a, b: TGuid): Boolean;
public
{ Public declarations }
procedure RewriteVideo(const SourceFileName, DestFileName: string);
end;
var
MainForm: TMainForm;
implementation
uses
DirectShow, ActiveX;
{$R *.dfm}
procedure TMainForm.FormCreate(Sender: TObject);
begin
CoInitialize(nil)
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
CoUninitialize
end;
procedure TMainForm.SourceSpeedButtonClick(Sender: TObject);
begin
if OpenDialog.Execute then
SourceEdit.Text:=OpenDialog.FileName
end;
procedure TMainForm.DestSpeedButtonClick(Sender: TObject);
begin
if SaveDialog.Execute then
DestEdit.Text:=SaveDialog.FileName
end;
procedure TMainForm.ActionButtonClick(Sender: TObject);
begin
RewriteVideo(SourceEdit.Text, DestEdit.Text)
end;
procedure TMainForm.RewriteVideo(const SourceFileName,
DestFileName: string);
var
Builder: ICaptureGraphBuilder2;
Graph: IGraphBuilder;
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;
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);
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;
Graph.QueryInterface(IID_IMediaControl, MediaControl);
Graph.QueryInterface(IID_IMediaEvent, MediaEvent);
MediaControl.Run;
MediaEvent.WaitForCompletion(INFINITE, EVCode);
MediaControl.Stop
end;
function TMainForm.SameGUID(const a, b: TGuid): Boolean;
var
i: Byte;
begin
Result:=True;
if a.D1<>b.D1 then
Result:=False
else
if a.D2<>b.D2 then
Result:=False
else
if a.D3<>b.D3 then
Result:=False
else
for i:=0 to 7do
if a.D4<>b.D4 then
begin
Result:=False;
Exit
end
end;
end.
------------
提取音频是参照另一位富翁的提示!
那个是要取视频流,这个是要音频流。
将if not SameGUID(MediaType.majortype, MediaType_Video) then
改为if not SameGUID(MediaType.majortype, MediaType_Audio) then
你好!
在论坛上,看到你提供的方法!我试了一下,从DAT文件抽取的AVI文件,用系统播放机无法播放,在抽取音频文件后,也无法播放,这是什么原因呢?
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TMainForm = class(TForm)
SourceEdit: TEdit;
DestEdit: TEdit;
SourceSpeedButton: TSpeedButton;
DestSpeedButton: TSpeedButton;
ActionButton: TButton;
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
procedure SourceSpeedButtonClick(Sender: TObject);
procedure DestSpeedButtonClick(Sender: TObject);
procedure ActionButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
function SameGUID(const a, b: TGuid): Boolean;
public
{ Public declarations }
procedure RewriteVideo(const SourceFileName, DestFileName: string);
end;
var
MainForm: TMainForm;
implementation
uses
DirectShow, ActiveX;
{$R *.dfm}
procedure TMainForm.FormCreate(Sender: TObject);
begin
CoInitialize(nil)
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
CoUninitialize
end;
procedure TMainForm.SourceSpeedButtonClick(Sender: TObject);
begin
if OpenDialog.Execute then
SourceEdit.Text:=OpenDialog.FileName
end;
procedure TMainForm.DestSpeedButtonClick(Sender: TObject);
begin
if SaveDialog.Execute then
DestEdit.Text:=SaveDialog.FileName
end;
procedure TMainForm.ActionButtonClick(Sender: TObject);
begin
RewriteVideo(SourceEdit.Text, DestEdit.Text)
end;
procedure TMainForm.RewriteVideo(const SourceFileName,
DestFileName: string);
var
Builder: ICaptureGraphBuilder2;
Graph: IGraphBuilder;
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;
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);
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;
Graph.QueryInterface(IID_IMediaControl, MediaControl);
Graph.QueryInterface(IID_IMediaEvent, MediaEvent);
MediaControl.Run;
MediaEvent.WaitForCompletion(INFINITE, EVCode);
MediaControl.Stop
end;
function TMainForm.SameGUID(const a, b: TGuid): Boolean;
var
i: Byte;
begin
Result:=True;
if a.D1<>b.D1 then
Result:=False
else
if a.D2<>b.D2 then
Result:=False
else
if a.D3<>b.D3 then
Result:=False
else
for i:=0 to 7do
if a.D4<>b.D4 then
begin
Result:=False;
Exit
end
end;
end.
------------
提取音频是参照另一位富翁的提示!
那个是要取视频流,这个是要音频流。
将if not SameGUID(MediaType.majortype, MediaType_Video) then
改为if not SameGUID(MediaType.majortype, MediaType_Audio) then