VC 进度条 Media encoder时间获取问题

mangshe0 2008-05-24 07:00:14
VC 进度条我知道使用wndProgress 但是在设置时间上只是知道怎么设置一个固定的时间,
请问 如何获取Media Encoder 转换视频文件格式时所需要的时间呢?
谢谢了,希望能够给个案例谢谢谢谢。
...全文
56 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
mangshe0 2008-05-25
  • 打赏
  • 举报
回复
mark

//格式转换
void CFormatChange::OnOK()
{
// TODO: Add extra validation here
char str1[260],str2[260];
GetDlgItemText(IDC_EFile,str1,MAX_PATH);
GetDlgItemText(IDC_Epublish,str2,MAX_PATH);
UpdateData(TRUE);
m_filename=m_filename+".wmv";
//UpdateData(FALSE);

HRESULT hr;
IWMEncoder* pEncoder;
IWMEncSourceGroupCollection* pSrcGrpColl;
IWMEncSourceGroup* pSrcGrp;
IWMEncSource* pSrc;
IWMEncSource* pSrcAud;
IWMEncVideoSource* pSrcVid;
IWMEncProfileCollection* pProColl;
IWMEncProfile* pPro;
IWMEncFile* pFile;
IWMEncAttributes* pAttr;
IWMEncDisplayInfo* pDispInfo;
CComBSTR bstrName = NULL;
long lCount;
int i;

//进度条
CProgressWnd wndProgress(this, "文件转换", TRUE);
wndProgress.SetRange(0,500000);//此参数要与下面的循环一致
wndProgress.SetText("文件正在转换...\n\n"
"这需要些时间,请稍后.");


// 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 the source group collection.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_SourceGroupCollection(&pSrcGrpColl);
}

// Add a source group to the collection.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrpColl->Add(CComBSTR("SG_1"), &pSrcGrp);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_AUDIO, &pSrcAud);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_VIDEO, &pSrc);
}

// Retrieve an IWMEncVideoSource pointer.
if ( SUCCEEDED( hr ) )
{
hr = pSrc->QueryInterface(IID_IWMEncVideoSource, (void**)&pSrcVid);
}

// Add a video and audio source to the source group.
if ( SUCCEEDED( hr ) )
{
hr = pSrcAud->SetInput(CComBSTR(str1));
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->SetInput(CComBSTR(str1));
}

// Specify the cropping margins.
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->put_CroppingBottomMargin(5);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->put_CroppingTopMargin(5);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->put_CroppingLeftMargin(3);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcVid->put_CroppingRightMargin(3);
}

// Fill in the description object members.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_DisplayInfo(&pDispInfo);
}
if ( SUCCEEDED( hr ) )
{
hr = pDispInfo->put_Author(CComBSTR("Author Name"));
}
if ( SUCCEEDED( hr ) )
{
hr = pDispInfo->put_Copyright(CComBSTR("Copyright"));
}
if ( SUCCEEDED( hr ) )
{
hr = pDispInfo->put_Description(CComBSTR("A description"));
}
if ( SUCCEEDED( hr ) )
{
hr = pDispInfo->put_Rating(CComBSTR("Rating"));
}
if ( SUCCEEDED( hr ) )
{
hr = pDispInfo->put_Title(CComBSTR("The Title"));
}

// Add an attribute to the collection.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_Attributes(&pAttr);
}
if ( SUCCEEDED( hr ) )
{
hr = pAttr->Add(CComBSTR("URL"), CComVariant("IP Address"));
}

// Specify a file object in which to save encoded content.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_File(&pFile);
}
if ( SUCCEEDED( hr ) )
{
hr = pFile->put_LocalFileName(CComBSTR(str2+m_filename));
}

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

// Start the encoding process.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->PrepareToEncode(VARIANT_TRUE);
}
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->Start();
// Keep the console window open.
// printf("When encoding stops, press a key to close the console window.");
}
//进度条
for (int p = 0; p < 500000; p++)
{
//sleep(100);
wndProgress.StepIt();
wndProgress.PeekAndPump();
if (wndProgress.Cancelled())
{
MessageBox("您取消了转换");
break;
}
}

// Stop the encoding process.
/* if ( SUCCEEDED( hr ) )
{
// Wait for a key press.
while(!kbhit())
_asm nop;

hr = pEncoder->Stop();
}
*/



if ( SUCCEEDED( hr ) )
{
hr = pEncoder->Stop();
}
// Release pointers.
if ( pSrcGrpColl )
{
pSrcGrpColl->Release();
pSrcGrpColl = NULL;
}
if ( pSrcGrp )
{
pSrcGrp->Release();
pSrcGrp = NULL;
}
if ( pProColl )
{
pProColl->Release();
pProColl = NULL;
}
if ( pPro )
{
pPro->Release();
pPro = NULL;
}
if ( pFile )
{
pFile->Release();
pFile = NULL;
}
if ( pSrcAud )
{
pSrcAud->Release();
pSrcAud = NULL;
}
if ( pSrcVid )
{
pSrcVid->Release();
pSrcVid = NULL;
}
if ( pSrc )
{
pSrc->Release();
pSrc = NULL;
}
if ( pAttr )
{
pAttr->Release();
pAttr = NULL;
}
if ( pDispInfo )
{
pDispInfo->Release();
pDispInfo = NULL;
}
if ( pEncoder )
{
pEncoder->Release();
pEncoder = NULL;
}
// MessageBox("视频转换完毕");
CDialog::OnOK();
}

2,586

社区成员

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

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