想人民币购买用directshow实时采集图像压缩为mpeg-1的代码! (0分)

  • 主题发起人 主题发起人 oldfly
  • 开始时间 开始时间
O

oldfly

Unregistered / Unconfirmed
GUEST, unregistred user!
这是dspack2.1的demo实例videocap!实例中是存储为avi文件,我想实时存为mpeg-1或mpeg-2文件,要如何实现?采集卡不带压缩功能!我要求的实时图像只要320×240、25帧、
RGB24能不延时就成(cpu p3/500以上)!解决的代码要多少钱,能行我就汇款!
我的Email:wb@hhjc.com或hhjcwb@sina.com

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;
OutPutFileName: TLabel;
StatusBar: TStatusBar;
Timer: TTimer;
StopButton: TButton;
AudioCapFilters: TListBox;
AudioSourceFilter: TFilter;
Label1: TLabel;
Label2: TLabel;
VideoFormats: TListBox;
AudioFormats: TListBox;
Label3: TLabel;
Label4: TLabel;
InputLines: TComboBox;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure VideoCapFiltersClick(Sender: TObject);
procedure StartButtonClick(Sender: TObject);
procedure CapFileButtonClick(Sender: TObject);
procedure StopButtonClick(Sender: TObject);
procedure TimerTimer(Sender: TObject);
procedure AudioCapFiltersClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;


var
MainForm: TMainForm;
CapEnum: TSysDevEnum;
VideoMediaTypes, AudioMediaTypes: TEnumMediaType;
CapFile: WideString = 'c:/capture.avi';
implementation

{$R *.dfm}

{ TMainForm }

procedure TMainForm.FormCreate(Sender: TObject);
var i: integer;
begin

CapEnum := TSysDevEnum.Create(CLSID_VideoInputDeviceCategory);
for i := 0 to CapEnum.CountFilters - 1do

VideoCapFilters.Items.Add(CapEnum.Filters.FriendlyName);

CapEnum.SelectGUIDCategory(CLSID_AudioInputDeviceCategory);
for i := 0 to CapEnum.CountFilters - 1do

AudioCapFilters.Items.Add(CapEnum.Filters.FriendlyName);

VideoMediaTypes := TEnumMediaType.Create;
AudioMediaTypes := TEnumMediaType.Create;
end;


procedure TMainForm.FormDestroy(Sender: TObject);
begin

CapEnum.Free;
Timer.Enabled := false;
VideoMediaTypes.Free;
AudioMediaTypes.Free;
end;


// Select the video Source
procedure TMainForm.VideoCapFiltersClick(Sender: TObject);
var
PinList: TPinList;
i: integer;
begin

CapEnum.SelectGUIDCategory(CLSID_VideoInputDeviceCategory);
if VideoCapFilters.ItemIndex <> -1 then

begin

VideoSourceFilter.BaseFilter.Moniker := CapEnum.GetMoniker(VideoCapFilters.ItemIndex);
VideoSourceFilter.FilterGraph := CaptureGraph;
CaptureGraph.Active := true;
PinList := TPinList.Create(VideoSourceFilter as IBaseFilter);
VideoFormats.Clear;
VideoMediaTypes.Assign(PinList.First);
for i := 0 to VideoMediaTypes.Count - 1do

VideoFormats.Items.Add(VideoMediaTypes.MediaDescription);
CaptureGraph.Active := false;
PinList.Free;
StartButton.Enabled := true;
end;

end;


// Select the audio Source
procedure TMainForm.AudioCapFiltersClick(Sender: TObject);
var
PinList: TPinList;
i, LineIndex: integer;
ABool: LongBool;
begin

CapEnum.SelectGUIDCategory(CLSID_AudioInputDeviceCategory);
if AudioCapFilters.ItemIndex <> -1 then

begin

AudioSourceFilter.BaseFilter.Moniker := CapEnum.GetMoniker(AudioCapFilters.ItemIndex);
AudioSourceFilter.FilterGraph := CaptureGraph;
CaptureGraph.Active := true;
PinList := TPinList.Create(AudioSourceFilter as IBaseFilter);
AudioFormats.Clear;
i := 0;
while i < PinList.Countdo

if PinList.PinInfo.dir = PINDIR_OUTPUT then

begin

AudioMediaTypes.Assign(PinList.Items);
PinList.Delete(i);
end else
inc(i);

for i := 0 to AudioMediaTypes.Count - 1do

begin

AudioFormats.Items.Add(AudioMediaTypes.MediaDescription);
end;


CaptureGraph.Active := false;
InputLines.Clear;
LineIndex := -1;
for i := 0 to PinList.Count - 1do

begin

InputLines.Items.Add(PinList.PinInfo.achName);
with (PinList.Items as IAMAudioInputMixer)do
get_Enable(ABool);
if ABool then
LineIndex := i;
end;

InputLines.ItemIndex := LineIndex;
PinList.Free;
StartButton.Enabled := true;
end;

end;


// Start Capture
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.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
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;


// Select the Ouput file
procedure TMainForm.CapFileButtonClick(Sender: TObject);
begin

if SaveDialog.Execute then

begin

CapFile := SaveDialog.FileName;
OutPutFileName.Caption := 'c:/capture.avi';
end;

end;


// Stop Capture
procedure TMainForm.StopButtonClick(Sender: TObject);
begin

Timer.Enabled := false;
StopButton.Enabled := false;
StartButton.Enabled := true;
CaptureGraph.Stop;
CaptureGraph.Active := False;
AudioFormats.Enabled := true;
AudioCapFilters.Enabled := true;
VideoFormats.Enabled := true;
VideoCapFilters.Enabled := true;

end;


// Timer
procedure TMainForm.TimerTimer(Sender: TObject);
var
position: int64;
Hour, Min, Sec, MSec: Word;
const MiliSecInOneDay = 86400000;
begin

if CaptureGraph.Active then

begin

with CaptureGraph as IMediaSeekingdo

GetCurrentPosition(position);
DecodeTime(position div 10000 / MiliSecInOneDay, Hour, Min, Sec, MSec);
StatusBar.SimpleText := Format('%d:%d:%d:%d',[Hour, Min, Sec, MSec]);
end;


end;



end.
 
实时压缩成MPEG根本不可能,现在最好最快的压缩转换软件最多也不过是2X的速度.也就是
1分钟的图像得用2分钟压缩.
除非硬件!
 
有一个控件可以
可惜是老外的
 
我也需要,帮你顶一下,呵呵!
 
3cs.你的问题还没解决吗?用BBMPEG吧
 
前段时间刚好做过留下QQ.我们联系点我的QQ是36525991
 
LRESULT __stdcall MyDec(LPVOID InData,int InBufSize,LPVOID OutData,int OutWidth,int OutHeight)
{
BITMAPINFO m_BmpU, m_BmpC;
HIC hIC=0;
LRESULT lRet=0;
//char InfoBuf[1000];
//构造特定结构(参数根据本人反汇编的结果得到,危险极大〕
m_BmpC.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
m_BmpC.bmiHeader.biWidth=OutWidth;
m_BmpC.bmiHeader.biHeight=OutHeight;
m_BmpC.bmiHeader.biPlanes=0x1;
m_BmpC.bmiHeader.biBitCount=0x18;
m_BmpC.bmiHeader.biCompression=0x3234504D;
m_BmpC.bmiHeader.biSizeImage=InBufSize;
m_BmpC.bmiHeader.biXPelsPerMeter=0x0;
m_BmpC.bmiHeader.biYPelsPerMeter=0x0;
m_BmpC.bmiHeader.biClrUsed=0x0;
m_BmpC.bmiHeader.biClrImportant=0x0;
m_BmpU.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
m_BmpU.bmiHeader.biWidth=OutWidth;
m_BmpU.bmiHeader.biHeight=OutHeight;
m_BmpU.bmiHeader.biPlanes=0x1;
m_BmpU.bmiHeader.biBitCount=0x18;
m_BmpU.bmiHeader.biCompression=0x0;
m_BmpU.bmiHeader.biSizeImage=OutWidth*OutHeight*3;
m_BmpU.bmiHeader.biXPelsPerMeter=0x0;
m_BmpU.bmiHeader.biYPelsPerMeter=0x0;
m_BmpU.bmiHeader.biClrUsed=0x0;
m_BmpU.bmiHeader.biClrImportant=0x0;
//热身一下,我也不知道为什么要这样做
/*
hIC=ICOpen(0x63646976,0x3234504D,0x01);
//为零就没搞头了,马上走人
if (hIC==0) {return 1;}
lRet=ICSendMessage(hIC,0x5000,(unsigned long) InfoBuf,0x78);
if (lRet==0) {return 2;}
lRet=ICSendMessage(hIC,0x5000,0x0,0x0);
if (lRet==0) {return 3;}
lRet=ICClose(hIC);
if (lRet!=0) {return 4;}
*/
//开始进行解码的工作
hIC=ICOpen(0x63646976,0x3234504D,0x02);
if (hIC==0) {return 5;}
lRet=ICSendMessage(hIC,0x400C,(unsigned long)&amp;m_BmpC.bmiHeader,(unsigned long)&amp;m_BmpU.bmiHeader);
if (lRet!=0) {return 6;}
lRet=ICDecompress(hIC,0,&amp;m_BmpC.bmiHeader,InData,&amp;m_BmpU.bmiHeader,OutData);
if (lRet!=0) {return 7;}
lRet=ICClose(hIC);
if (lRet!=0) {return 8;}
//搞完收工
return 0;
}
 
http://members.cox.net/beyeler/bbmpeg.html
May-25-01, updated bbMPEG.DLL to version 1.24 beta 18, and AVI2MPG2.EXE, AVI2MPG2_VFW.EXE to version 1.24 beta 13.
全部免费代码
 
http://www.msbsoftware.it/mpegpas/
这个也可以解决上面的问题.
 
后退
顶部