MEDIA ENCODER SAMPLE的问题

gdbarry 2008-03-25 01:06:12
毕业设计写一个远程教学的软件

要实现屏幕录像好视频录像功能

用MEDIA ENCODER 9 SDK,屏幕录像没问题

用摄像头做为数据源的时候,运行到

hr = pEncoder->PrepareToEncode(VARIANT_TRUE);

出现堆栈错误,中断了,用RELEASE发布可以过

但是到,hr = pEncoder->Start();
返回错误代码
0xC00D1B71

SDK文档没说明,GOOGLE给出unsupported file formats or invalid files.

调试了很久也没解决。。。救救我

还有个问题是调用Windows Media Encoder UI的时候

加入WMEncSourcesPage的时候就出错。。。

代码都是SDK给的SAMPLE,也是简练到不能再简了。。HELP




// media5.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include <windows.h>
#include <atlbase.h>
#include <comdef.h>
#include "C:\WMSDK\WMEncSDK9\include\wmencode.h"
#include "C:\WMSDK\WMEncSDK9\include\wmdevctl.h"
#include <conio.h> // for kbhit()



int _tmain(int argc, _TCHAR* argv[])
{

HRESULT hr;
IWMEncoder2* pEncoder;
IWMEncSourceGroupCollection* pSrcGrpColl;
IWMEncSourceGroup* pSrcGrp;
IWMEncSourceGroup2* pSrcGrp2;
IWMEncSource* pSrcAud;
IWMEncSource* pSrcVid;
IWMEncFile* pFile;
IWMEncProfileCollection* pProColl;
IWMEncProfile* pPro;
IWMEncDeviceControlCollection* pDCColl;
IWMEncDeviceControl* pDControl;
IWMEncDeviceControlPlugin* pDCPlugin;
IWMEncEditDecisionList* pEDList;
IWMEncEditDecisionData* pEDData;

CComBSTR bstrName = NULL;

long lCount;
int i;

// Initialize the COM library and retrieve a pointer
// to an IWMEncoder interface.
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:\\DeviceOutput2.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://Realtek AC97 Audio"));
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->SetInput(CComBSTR("Device://USB PC Camera 301P"));
}

// 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://USB PC Camera 301P"));
}

// Initialize the encoding session.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->PrepareToEncode(VARIANT_TRUE);
}

// Get the plug-in from the device.
if ( SUCCEEDED( hr ) )
{
hr = pDControl->GetDeviceControlPlugin((IUnknown**)&pDCPlugin);
}

// 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"));
}

// Wait for the user to press a key to start encoding.
printf("Press a key to start encoding.");

// Wait for a key press.
while(!kbhit())
_asm nop;

// Start encoding.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->Start();

// Stop the encoding process.
if ( SUCCEEDED( hr ) )
{
// Wait for the user to press a key to stop encoding.
printf("Press a key to stop encoding.");

// Wait for a key press.
while(!kbhit())
_asm nop;

hr = pEncoder->Stop();
}

}
printf("\n%x",hr);

// Release pointers.
if ( pSrcGrpColl )
{
pSrcGrpColl->Release();
pSrcGrpColl = NULL;
}
if ( pSrcGrp )
{
pSrcGrp->Release();
pSrcGrp = NULL;
}
if ( pSrcGrp2 )
{
pSrcGrp2->Release();
pSrcGrp2 = NULL;
}
//if ( pSrcAud )
//{
// pSrcAud->Release();
// pSrcAud = NULL;
//}
if ( pSrcVid )
{
pSrcVid->Release();
pSrcVid = NULL;
}
if ( pFile )
{
pFile->Release();
pFile = NULL;
}
if ( pProColl )
{
pProColl->Release();
pProColl = NULL;
}
if ( pPro )
{
pPro->Release();
pPro = NULL;
}
if ( pDCColl )
{
pDCColl->Release();
pDCColl = NULL;
}
if ( pDControl )
{
pDControl->Release();
pDControl = NULL;
}
if ( pDCPlugin )
{
pDCPlugin->Release();
pDCPlugin = NULL;
}
if ( pEDList )
{
pEDList->Release();
pEDList = NULL;
}
if ( pEDData )
{
pEDData->Release();
pEDData = NULL;
}
if ( pEncoder )
{
pEncoder->Release();
pEncoder = NULL;
}

return 0;
}


...全文
223 3 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
vision_sky 2010-09-08
  • 打赏
  • 举报
回复
解决了吗?
meiZiNick 2008-04-30
  • 打赏
  • 举报
回复
不知,帮顶
gdbarry 2008-03-26
  • 打赏
  • 举报
回复
我顶.... :(
相关推荐
发帖
图形处理/算法

1.9w+

社区成员

VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
帖子事件
创建了帖子
2008-03-25 01:06
社区公告
暂无公告