windows mediea encoder 开发,取设备属性配置出错。

truelove7283159 2008-01-10 08:04:08
SDK中的例子,但是我这里执行的时候始终出现一个非法访问的错误。
猜测是没有父窗口,不知道各位大虾是否能帮我看看,谢谢。


// Include libraries.
#include <windows.h>
#include <atlbase.h>
#include "wmencode.h"

// Declare variables.
HRESULT hr;
IWMEncoder *pEncoder;
IWMEncSourceGroupCollection *pSrcGrpColl;
IWMEncSourceGroup *pSrcGrp;
IWMEncSource *pVidSrc, *pAudSrc;
IWMEncProfileCollection *pProColl;
IWMEncProfile *pPro;
IUnknown *pPlugin = NULL;
ISpecifyPropertyPages *pPages = NULL;
CAUUID uuid;
HWND m_hWnd = 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_IWMEncoder, (void **) &pEncoder);
}

// Retrieve a pointer to an IWMEncSourceGroupCollection
// interface.
if (SUCCEEDED(hr))
{
hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
}

// Add an empty source group to the collection.
if (SUCCEEDED(hr))
{
hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
}

// Add video and audio streams to the source group.
if (SUCCEEDED(hr))
{
hr = pSrcGrp->AddSource(WMENC_VIDEO, &pVidSrc);
}

if (SUCCEEDED(hr))
{
hr = pSrcGrp->AddSource(WMENC_AUDIO, &pAudSrc);
}

// Specify the plug-in to use for capturing the streams.
if (SUCCEEDED(hr))
{
hr = pVidSrc->SetInput(CComBSTR("DEVICE://Default_Video_Device"));
}

if (SUCCEEDED(hr))
{
hr = pAudSrc->SetInput(CComBSTR("DEVICE://Default_Audio_Device"));
}

// Loop through the profile collection and retrieve a specific profile.
// Replace the following profile name with the profile you want.
if (SUCCEEDED(hr))
{
hr = pEncoder->get_ProfileCollection(&pProColl);
}

if (SUCCEEDED(hr))
{
hr = pProColl->get_Count(&lCount);
}

for (i = 0; i < lCount; i++)
{
CComBSTR bstrName(" ");
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)
{
if (SUCCEEDED(hr))
{
hr = pSrcGrp->put_Profile(CComVariant(pPro));
}
break;
}
}

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

// Retrieve the plug-in object.
if (SUCCEEDED(hr))
{
hr = pVidSrc->GetSourcePlugin(&pPlugin);
}

// Call QueryInterface to verify whether the plug-in supports
// property pages. If it does, retrieve a pointer to the
// ISpecifyPropertyPages interface, and fill an array of GUID
// values in which each GUID specifies the CLSID of each property
// page that can be displayed for this object.
if (SUCCEEDED(hr))
{
hr = pPlugin->QueryInterface(IID_ISpecifyPropertyPages, (LPVOID*) &pPages);
}

if (SUCCEEDED(hr))
{
hr = pPages->GetPages(&uuid);
}

// Invoke a dialog box to display.
if (SUCCEEDED(hr))
{
hr = OleCreatePropertyFrame(m_hWnd, // You must create the parent window.
200, // Horizontal position for the dialog box.
200, // Vertical position for the dialog box.
CComBSTR("name"), // String used for the dialog box caption.
1, // Number of pointers passed in pPlugin.
&pPlugin, // Pointer to the plug-in.
uuid.cElems, // Number of property pages.
uuid.pElems, // Array of property page CLSIDs.
LOCALE_USER_DEFAULT, // Locale ID for the dialog box.
0, // Reserved.
NULL // Reserved.
);

///《=================================================================OleCreatePropertyFrame crash了。
}

// Release memory.
if (uuid.pElems)
{
CoTaskMemFree(uuid.pElems);
}

// Release pointers.
if (pSrcGrpColl)
{
pSrcGrpColl->Release();
pSrcGrpColl = NULL;
}

if (pSrcGrp)
{
pSrcGrp->Release();
pSrcGrp = NULL;
}

if (pVidSrc)
{
pVidSrc->Release();
pVidSrc = NULL;
}

if (pAudSrc)
{
pAudSrc->Release();
pAudSrc = NULL;
}

if (pProColl)
{
pProColl->Release();
pProColl = NULL;
}

if (pPro)
{
pPro->Release();
pPro = NULL;
}

if (pPlugin)
{
pPlugin->Release();
pPlugin = NULL;
}

if (pPages)
{
pPages->Release();
pPages = NULL;
}

if (pEncoder)
{
pEncoder->Release();
pEncoder = NULL;
}


sdk下载地址、
http://www.microsoft.com/downloads/details.aspx?FamilyID=000a16f5-d62b-4303-bb22-f0c0861be25b&DisplayLang=en
http://www.microsoft.com/downloads/details.aspx?FamilyID=acddaae1-93a9-4dd5-aaa2-5fb28c3ba43a&displaylang=zh-cn

windows mediea encoder下载地址
http://www.microsoft.com/downloads/details.aspx?familyid=5691BA02-E496-465A-BBA9-B2F1182CDF24&displaylang=zh-cn

...全文
149 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
nihao38 2008-01-11
  • 打赏
  • 举报
回复
帮你顶

truelove7283159 2008-01-11
  • 打赏
  • 举报
回复
这个例子我有的。
没有相关帮助阿,郁闷阿。
dyw 2008-01-10
  • 打赏
  • 举报
回复
dyw 2008-01-10
  • 打赏
  • 举报
回复
找个例子研究一下。

19,466

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧