捕捉USB摄像头转ASF时候视频格式不能改变 ( 积分: 300 )

  • 主题发起人 主题发起人 donexie
  • 开始时间 开始时间
D

donexie

Unregistered / Unconfirmed
GUEST, unregistred user!
问题:
可以取得视频格式列表,可是选择后(比如选择640X480)没有作用,录下来的是320X240的视频格式.300分求解.

代码:

begin


GetMem(MySysPath,255);
GetSystemDirectory(MySysPath,255);
ASFWriter.FileName:= mysyspath+'/'+DateTimetostr((now()))+'.asf';
// 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

CheckDSError(RenderStream(@PIN_CATEGORY_PREVIEW, nil, VideoSourceFilter as IBaseFilter, nil, VideoWindow as IBaseFilter));
CheckDSError(RenderStream(@PIN_CATEGORY_CAPTURE, nil, VideoSourceFilter as IBaseFilter, nil, ASFWriter as IBaseFilter));
CheckDSError(RenderStream(nil, nil, AudioSourceFilter as IBaseFilter, nil, ASFWriter as IBaseFilter));

end;
 
问题:
可以取得视频格式列表,可是选择后(比如选择640X480)没有作用,录下来的是320X240的视频格式.300分求解.

代码:

begin


GetMem(MySysPath,255);
GetSystemDirectory(MySysPath,255);
ASFWriter.FileName:= mysyspath+'/'+DateTimetostr((now()))+'.asf';
// 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

CheckDSError(RenderStream(@PIN_CATEGORY_PREVIEW, nil, VideoSourceFilter as IBaseFilter, nil, VideoWindow as IBaseFilter));
CheckDSError(RenderStream(@PIN_CATEGORY_CAPTURE, nil, VideoSourceFilter as IBaseFilter, nil, ASFWriter as IBaseFilter));
CheckDSError(RenderStream(nil, nil, AudioSourceFilter as IBaseFilter, nil, ASFWriter as IBaseFilter));

end;
 
改变profile就行了!
 
愿闻其详.
 
楼上的说的对,看下面代码
function SetProfile(pWriter: IWMWriter;lWidth,lHeight,bitRate:Integer): HRESULT;
var
hr: HRESULT;
pvi: PVideoInfoHeader;
lCount: DWord;
a: TGUID;
lpv:IWMPropertyVault;
lvalue1:LongBool;
lValue2:DWORD;
lFile:TFileStream;
lbuf:PWideChar;
lvalt:IWMPropertyVault;
lvbrenabled:Boolean;
lvbrconfig:DWORD;
begin

hr := WMCreateProfileManager(pProfileMgr);
if FAILED(hr) then

begin

ShowMessage(format('Error on Call WMCreateProfileManager (%x)',
));
Result := hr;
exit;
end;

hr := pProfileMgr.CreateEmptyProfile(WMT_VER_7_0, pProfile);
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pProfileMgr.CreateEmptyProfile (%x)',
));
Result := hr;
exit;
end;

hr := pProfile.SetName('Video1');
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pProfile.SetName (%x)',
));
Result := hr;
exit;
end;

hr := pProfile.SetDescription('Unionsoft WMV ProFiles');
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pProfile.SetDescription (%x)',
));
Result := hr;
exit;
end;


hr := pProfile.CreateNewStream(WMMEDIATYPE_Video, pStream);
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pProfile.CreatenewStream (%x)',
));
Result := hr;
exit;
end;


// Get the media properties interface for the new stream.
hr := pStream.QueryInterface(IID_IWMVideoMediaProps, pMediaProps);
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pStream.QueryInterface (%x)',
));
Result := hr;
exit;
end;


// Get the media-type structure.
// First, get the size of the media-type structure.
hr := pMediaProps.GetMediaType(nil, cbMediaType);
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pMediaProps.GetMediaType (%x)',
));
Result := hr;
exit;
end;


// Allocate memory for the structure based on the retrieved size.
// pMediaType := (WM_MEDIA_TYPE * )new BYTE[cbMediaType];
GetMem(pMediaType, cbMediatype);
// Retrieve the media-type structure.
hr := pMediaProps.GetMediaType(pMediaType, cbMediaType);
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pMediaProps.GetMediaType (1) (%x)',
));
Result := hr;
exit;
end;


// Change the video size to 640 x 480.
pvi := PVideoInfoHeader(pMediaType.pbFormat);
// ShowMessage(format('%d,%d,%d,%d',[pvi.bmiHeader.biWidth,pvi.bmiheader.biHeight,pvi.bmiHeader.biBitCount,pvi.bmiHeader.biSizeImage]));
pvi.bmiHeader.biWidth := lWidth;
//设置视频的宽
pvi.bmiHeader.biHeight := lHeight;
//设置视频的高
pvi.bmiHeader.biSizeImage := pvi.bmiHeader.biWidth * pvi.bmiHeader.biHeight * pvi.bmiHeader.biBitCount div 8;
pvi.rcSource := RECT(0, 0, lWidth,lHeight);
pvi.rcTarget := RECT(0, 0, lWidth,lHeight);
pvi.dwBitRate := bitRate;
pvi.bmiHeader.biCompression:=WMMEDIASUBTYPE_WMV1.D1;
pMediaType.subtype:=WMMEDIASUBTYPE_WMV1;
pMediaProps.SetMaxKeyFrameSpacing(30000000);
pMediaProps.SetQuality(100);
hr := pMediaProps.SetMediaType(pMediaType);
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pMediaProps.SetMediaType (%x)',
));
Result := hr;
exit;
end;


// Release the media properties interface and delete the structure.
pMediaProps := nil;
freeMem(pMediaType);

pMediaType := nil;

// Set the bit rate to 200.

hr := pStream.SetBitrate(bitRate);
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pStream.SetBitrate (%x)',
));
Result := hr;
exit;
end;


pStream.SetBufferWindow($FFFFFFFF);
// Set the stream number.
hr := pStream.SetStreamNumber(1);
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pStream.SetStreamNumber (%x)',
));
Result := hr;
exit;
end;


// Include the new stream in the profile.
hr := pProfile.AddStream(pStream);
if FAILED(hr) then

begin

ShowMessage(format('Error on Call pProfile.AddStream (%x)',
));
Result := hr;
exit;
end;


pProfile.ReconfigStream(pStream);

pStream := nil;
hr:=pWriter.SetProfile(pProfile);
if Failed(hr) then

begin

ShowMessage(format('Error on Call pWriter.SetProfile (%x)',
));
Result := hr;
exit;
end;


// Release the mutual exclusion object.
pMutex := nil;

// TODO: Save the profile to a string, and save the string to a file.
// For more information, see To Save a Custom Profile.

// Release remaining interfaces.
pProfile := nil;

pProfileMgr := nil;
Result := S_OK;
end;
 
看Dspack自带的DEMO不是很清楚了吗?我对整体结构还需要时间来理解!?
 
我也遇到这个问题了

就是改变视频格式的分辨率 进行图像捕捉
可是捕捉的图像始终智能是320×240的分辨率,无法达到其他的分辨率(比如640×480)
是为什么 啊? 把视频参数设置的程序部分附在后面 请高手指点 谢谢了 :)

unit CaptureFrm;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls, ComCtrls, DSPack, ExtCtrls, Spin, FileCtrl, Jpeg, ShellApi,
DirectShow9, DSUtil;

type
TfmCapture = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
btnSave: TButton;
btnSave2: TButton;
btnClose: TButton;
OpenDialog1: TOpenDialog;
Panel1: TPanel;
VideoWindow1: TVideoWindow;
cbDevice: TComboBox;
cbFormats: TComboBox;
Label2: TLabel;
Label3: TLabel;
btnSetDevice: TBitBtn;
SpinEdit1: TSpinEdit;
Label4: TLabel;
FileListBox1: TFileListBox;
DirectoryListBox1: TDirectoryListBox;
Panel2: TPanel;
imgPreview: TImage;
DriveComboBox1: TDriveComboBox;
FilterGraph1: TFilterGraph;
SampleGrabber1: TSampleGrabber;
SaveDialog1: TSaveDialog;
SaveDialog2: TSaveDialog;
Filter1: TFilter;
Timer1: TTimer;
StatusBar1: TStatusBar;
Btn_Video_Property: TButton;
procedure btnCloseClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure btnSave2Click(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
procedure btnSetDeviceClick(Sender: TObject);
procedure cbDeviceChange(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure imgPreviewClick(Sender: TObject);
procedure FileListBox1Click(Sender: TObject);
procedure Btn_Video_PropertyClick(Sender: TObject);
procedure cbFormatsChange(Sender: TObject);
private
{ Private declarations }

public
{ Public declarations }
end;


var
fmCapture: TfmCapture;
//// function SetProfile(pWriter: IWMWriter;lWidth,lHeight,bitRate:Integer);
implementation
////function SetProfile(pWriter: IWMWriter;lWidth,lHeight,bitRate:Integer);

{$R *.dfm}

var
lastFile: String;
count: Integer;

CapEnum: TSysDevEnum;
VideoMediaTypes: TEnumMediaType;
begin
Saved: Boolean;


procedure TfmCapture.cbDeviceChange(Sender: TObject);
var
PinList: TPinList;
i: integer;
begin

CapEnum.SelectGUIDCategory(CLSID_VideoInputDeviceCategory);

if cbDevice.ItemIndex <> -1 then
begin

Filter1.BaseFilter.Moniker := CapEnum.GetMoniker(cbDevice.ItemIndex - 1);
Filter1.FilterGraph := FilterGraph1;
FilterGraph1.Active := true;
PinList := TPinList.Create(Filter1 as IBaseFilter);

cbFormats.Clear;
ShowPinPropertyPage(Handle, PinList.First);
VideoMediaTypes.Assign(PinList.First);

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

cbFormats.Items.Add(VideoMediaTypes.MediaDescription);

FilterGraph1.Active := false;
PinList.Free;

if cbFormats.Items.Count > 0 then

cbFormats.ItemIndex := 0;
end;

// StartButton.Enabled := true;

{ PinList := TPinList.Create(Filter1 as IBaseFilter);
if cbFormats.ItemIndex <> -1 then

with (PinList.First as IAMStreamConfig)do

SetFormat(VideoMediaTypes.Items[cbFormats.ItemIndex].AMMediaType^);
PinList.Free;
}
end;


procedure TfmCapture.cbFormatsChange(Sender: TObject);
begin

(Sender as TComboBox).Hint := (Sender as TComboBox).Text;
end;
 
楼上说的那个函数function SetProfile(pWriter: IWMWriter;lWidth,lHeight,bitRate:Integer): HRESULT;

怎么用啊 ?
请指教 QQ:19329748 谢谢 啊
 
问donexie

你的问题解决了吗?
麻烦告知联系方式
想共同探讨这个问题
问laoli,homelee,能告知具体方法吗?小弟现在急于解决这个问题 谢谢
 
to why0601
俺是业余搞搞啊 看来要持久战啦 我的QQ 12349234
 
后退
顶部