调用PrepareToEncode()时出错(100分)

O

oklys

Unregistered / Unconfirmed
GUEST, unregistred user!
我在使用Media Encode 9中VC的捕捉视频的例子代码时,执行到PrepareToEncode()就出错,我的环境是VC6和windows server 2003。请大侠帮忙!
我在网上搜索了很多资料,发现很多人都碰到这个问题,但是没有人出来回答,请高手现身!谢谢!
 
问题: 各位帮我看看这个Window Media Encoder SDK的问题 ( 积分: 100 )
分类: 多媒体

来自:do
nny2000, 时间: 2003-07-12 23:13:00, ID: 2024764
unit Unit1;

interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, WMEncoderLib_TLB, StdCtrls, ActiveX;

type
TForm1 = class(TForm)
Button1: TButton;
ComboBox1: TComboBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Encoder:WMEncoder;
SrcGrpColl:IWMEncSourceGroupCollection;
SrcGrp:IWMEncSourceGroup;
SrcVid,SrcAud:IWMEncSource;
EncodeFile:IWMEncFile;
ProColl:IWMEncProfileCollection;
// Pro :IWMEncProfile;
// i:integer;
begin

Encoder:=CoWMEncoder.Create;
SrcGrpColl:=Encoder.SourceGroupCollection;
SrcGrp:=SrcGrpColl.Add('SG_1');

SrcVid:=SrcGrp.AddSource(WMENC_VIDEO);
SrcAud:=SrcGrp.AddSource(WMENC_AUDIO);
SrcVid.SetInput('ScreenCap://ScreenCapture1','','');
SrcAud.SetInput('DEVICE://Default_Audio_Device',' ',' ');

EncodeFile:=Encoder.File_;
EncodeFile.LocalFileName:='C:/a.wmv';

ProColl:=Encoder.ProfileCollection;
{ for I:=1 to ProColl.Count-1do
begin

showmessage(ProColl.Item(i).Descrip);
end;
}
SrcGrp.Set_Profile(ProColl.item(ComboBox1.ItemIndex));

Encoder.PrepareToEncode(true);
Encoder.Start;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
Encoder:WMEncoder;
ProColl:IWMEncProfileCollection;
i:integer;
begin

Encoder:=CoWMEncoder.Create;
ProColl:=Encoder.ProfileCollection;
for I:=0 to ProColl.Count-1do
begin

ComboBox1.Items.Add(ProColl.Item(i).Name);
end;

ComboBox1.ItemIndex:=0;
end;

end.

使用的是9系列的SDK,程序编译通过,但是开始捕捉的时候,出错:“找不到可用于指定源的有效插件”。我搞了一天都没有明白什么原因

来自: jog81, 时间: 2003-07-14 22:54:00, ID: 2028903
不是很懂,只是我看你的代码,怎么程序启动时创建了控件,然后点击按键时又创建该控件呢?把下面的代码提前到implementation前试试!
Encoder:WMEncoder;
ProColl:IWMEncProfileCollection;
i:integer;


来自:do
nny2000, 时间: 2003-07-15 10:07:00, ID: 2029600
这个地方是贴上来得时候没有改得,但不影响。 在C#中完全正常,但是在Delphi中一样得实现就是要报上面得错误

来自: wbtvc, 时间: 2003-07-17 10:26:00, ID: 2035936
是声音设备的问题吧?
把SrcAud:=SrcGrp.AddSource(WMENC_AUDIO);
SrcAud.SetInput('DEVICE://Default_Audio_Device',' ',' ');
这两行去掉应该就可以了,试试


来自:do
nny2000, 时间: 2003-07-28 16:41:00, ID: 2065901
多人接受答案了。

得分大富翁: jog81-50,wbtvc-50,
 
我在VC中的代码是这样的:我也有把相当于SrcAud:=SrcGrp.AddSource(WMENC_AUDIO);
SrcAud.SetInput('DEVICE://Default_Audio_Device',' ',' ');
的语句去掉,但还是不行,请帮一下
hr = CoInitialize(NULL);
if ( SUCCEEDED( hr ) )
{
hr = CoCreateInstance(CLSID_WMEncoder,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWMEncoder2,
(void**) &pEncoder);
}
// Retrieve the source group collection.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
}
// Encode to a file.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_File(&pFile);
}
if ( SUCCEEDED( hr ) )
{
hr = pFile->put_LocalFileName(CComBSTR("C://DeviceOutput.wmv"));
}
// Add a source group to the collection.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->QueryInterface(IID_IWMEncSourceGroup2, (void**)&pSrcGrp2);
}
// Add a video and audio source to the source group.
/*if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_AUDIO, &pSrcAud);
}*/
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_VIDEO, &pSrcVid);
}
// Add the device as the audio source and video source.
/*if ( SUCCEEDED( hr ) )
{
hr = pSrcAud->SetInput(CComBSTR("Device://DEVICENAME"));
}*/
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->SetInput(CComBSTR("Device://Logitech QuickCam Pro 3000 (08B0)"));
}
// Choose a profile from the collection.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_ProfileCollection(&pProColl);
}
if ( SUCCEEDED( hr ) )
{
hr = pProColl->get_Count(&lCount);
}
for (i=0;
i<lCount;
i++)
{
if ( SUCCEEDED( hr ) )
{
hr = pProColl->Item(i, &pPro);
}
if ( SUCCEEDED( hr ) )
{
hr = pPro->get_Name(&bstrName);
}
if (_wcsicmp(bstrName,CComBSTR("Windows Media Video 8 for Local Area Network (384 Kbps)"))==0)
{
// Set the profile in the source group.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->put_Profile(CComVariant(pPro));
}
break;
}
}
// Retrieve the device control collection, then
add a device to it.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp2->get_DeviceControlCollection(&pDCColl);
}
if ( SUCCEEDED( hr ) )
{
hr = pDCColl->Add(&pDControl);
}
if ( SUCCEEDED( hr ) )
{
hr = pDControl->SetInput(CComBSTR("DeviceControl://Logitech QuickCam Pro 3000 (08B0)"));
}
// Initialize the encoding session.
if ( SUCCEEDED( hr ) )
{
AfxMessageBox("before pre encode");
hr = pEncoder->PrepareToEncode(VARIANT_TRUE);//程序到此处就不行了
//if(hr == S_OK)
// AfxMessageBox("input");
}
// Get the plug-in from the device.
if ( SUCCEEDED( hr ) )
{
hr = pDControl->GetDeviceControlPlugin((IUnknown**)&pDCPlugin);
if(hr == S_OK)
AfxMessageBox("input");
}
// Retrieve an IWMEncEditDecisionList interface from the device control plug-in.
if ( SUCCEEDED( hr ) )
{
hr = pDCPlugin->get_EditDecisionList(&pEDList);
}
// Create an EDL entry.
if ( SUCCEEDED( hr ) )
{
hr = pEDList->Add(&pEDData);
}
// Add attributes to the EDL entry specifying mark-in, mark-out,
// tape ID, and description information.
if ( SUCCEEDED( hr ) )
{
hr = pEDData->Add(CComBSTR("MarkIn"), CComVariant(262295));
}
if ( SUCCEEDED( hr ) )
{
hr = pEDData->Add(CComBSTR("MarkOut"), CComVariant(267268));
}
if ( SUCCEEDED( hr ) )
{
hr = pEDData->Add(CComBSTR("TapeID"), CComVariant("A"));
}
if ( SUCCEEDED( hr ) )
{
hr = pEDData->Add(CComBSTR("Description"), CComVariant("Scene 1"));
}
// Start encoding.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->Start();
}
 
我把把SrcAud:=SrcGrp.AddSource(WMENC_AUDIO);
SrcAud.SetInput('DEVICE://Default_Audio_Device',' ',' ');
去掉了也还是不行啊,再请高手出招!
 
顶部