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