如何保存image中的录像(100分)

  • 主题发起人 主题发起人 jzg2727
  • 开始时间 开始时间
J

jzg2727

Unregistered / Unconfirmed
GUEST, unregistred user!
我使用mediaplay播放avi的录像,播放的界面是一个panel,我在panel的旁边放置一个image
实时显示panel中的画面,我现在想保存image中显示的图像在硬盘中(avi格式),那位老兄
帮我解决一下.万分感谢
email:tianzhejt@163.com
 
怎么好像说的有点象VFW开发?你要干什么(达到什么目的)啦
 
不是VFW开发,使用VFW采集图像效果非常差,图像有延迟,有马赛克,而且每隔一段时间
还出现花屏,总之不实用,已被direct show 替代了,我是基于direct show进行录像的,
但现在确实很有困难,请各位富翁帮帮忙
 
哦,那有可能你的VFW的方法没控制好,我这里的还可以。
那我这里有delphiX的控件for delphi6的,你要不要?
还有我想知道directshow用什么方法捕捉视频呢?
 
老兄如果你有的delphiX的话就给我发一份
我的email: tianzhejt@163.com
至于direct show 用什么方法捕捉视频你可以先下载一个例程研究一下
http://www.delphi-jedi.org/DelphiGraphics/directx/downloads/dscap.zip
 
image1.Picture.SaveToFile('........');
 
image1.Picture.SaveToFile('........');

只能保存一张一张的图片,不能保存成一段录像
 
老兄既然用的是 direct show, 为什么不在directshow 里面加入一个 tee,然后
加入一个 file renderer, 就可以直接存盘了啊。为什么要在 image 里面抓图呢?
 
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.
 
我也想将采集卡,采集的图像转存成AVI或者MPG影像?如何做?
 
tianzhegs
你的代码不能将视频的图像改变呀,比如我要在视频图像加上文字
然后生成文件?
 
我也想在图像上加文字,但都被图像覆盖,我使用多文档窗口解决的,不过有白底的,效果不理想
 
看我的:
uses
aviwriter;

procedure TForm1.Button6Click(Sender: TObject);
var
list : TStringList;
Bmp : TBitmap;
I : integer;

begin

list :=TStringList.Create;

for I:=1 to 4do

begin

Bmp :=TBitmap.Create;
Bmp.LoadFromFile('d:/project/' + inttostr(i) + '.bmp');
list.AddObject('bitmap',TObject(Bmp));
aviwriter1.Bitmaps[i-1]:=TBitmap(slist.Objects[i-1]);
end;

aviwriter1.FileName:='d:/6.avi';
aviwriter1.FrameTime:=200;
aviwriter1.Write;
aviwriter1.Free;

end;




Slist.Free;
Bmp.Free;
end;


搞定了别忘了多给我点分。:) 最近穷死啦!
 
yangtsehua
你确定aviwriter1.Bitmaps[i-1]可以用吗,为什么我运行以后他总是说list index out of bounds(1)???
 
在panel的旁边放置一个image
实时显示panel中的画面,怎么实现?
 
后退
顶部