IWMEncProfile::get_MinPacketSize
![]() |
The get_MinPacketSize method retrieves the minimum size, in bytes, of the Windows Media data units generated during encoding.
Syntax
HRESULT get_MinPacketSize(
long* plMinPacketSize
);
Parameters
plMinPacketSize
[out] Pointer to a long containing the minimum packet size, in bytes.
Return Values
If the method succeeds, it returns S_OK. If it fails, it supports the IErrorInfo interface and returns an HRESULT error code.
| Return code | Number | Description |
| E_FAIL | 0x80004005 | An unspecified error occurred. |
| E_POINTER | 0x80004003 | The pointer to the packet size is NULL. |
Remarks
The get_MinPacketSize method retrieves the minimum size of the Advanced Systems Format (ASF) packets in the resulting Windows Media-based content. The value can be between 100 and 65,535 (in bytes), or 0. The actual packet size is calculated during the encoding process to optimize the content for streaming.
If the profile does not support uncompressed streams, the default value is 0. If the profile supports uncompressed streams, the default value is 65,535. The minimum packet size does not include the networking packet header or the Advanced Systems Format packet header.
Using a larger minimum packet size may reduce the file size of a Windows Media file by reducing the number of packets, and thus the overhead in the file. However, using a larger packet size may cause problems when streaming the content.
Example Code
// Include libraries.
#include <windows.h>
#include <atlbase.h> // Includes CComBSTR.
#include "wmencode.h"
// Declare variables.
HRESULT hr;
IWMEncoder* pEncoder;
IWMEncSourceGroupCollection* pSrcGrpColl;
IWMEncSourceGroup* pSrcGrp;
IWMEncSource* pAudSrc;
IWMEncSource* pVidSrc;
IWMEncProfileCollection* pProColl;
IWMEncProfile* pPro;
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 an audio and a video stream to the source group.
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_AUDIO, &pAudSrc);
}
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->AddSource(WMENC_VIDEO, &pVidSrc);
}
// Specify an .avi source file and a .wmv output file.
CComBSTR m_bstrInFile("C:\\filename.avi");
if ( SUCCEEDED( hr ) )
{
hr = pAudSrc->SetInput(m_bstrInFile);
}
if ( SUCCEEDED( hr ) )
{
hr = pVidSrc->SetInput(m_bstrInFile);
}
// Loop through the profile collection and retrieve a specific
// profile.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->get_ProfileCollection(&pProColl);
}
CComBSTR bstrName("");
CComBSTR bstrDesc("");
long lMaxPacketSz;
long lMinPacketSz;
short iMediaCount;
VARIANT_BOOL vbMultiBitrate;
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)
{
if ( SUCCEEDED( hr ) )
{
hr = pSrcGrp->put_Profile(CComVariant(pPro));
}
if ( SUCCEEDED( hr ) )
{
hr = pPro->get_Description(&bstrDesc);
}
if ( SUCCEEDED( hr ) )
{
hr = pPro->get_MaxPacketSize(&lMaxPacketSz);
}
if ( SUCCEEDED( hr ) )
{
hr = pPro->get_MinPacketSize(&lMinPacketSz);
}
if ( SUCCEEDED( hr ) )
{
hr = pPro->get_MediaCount(WMENC_VIDEO, &iMediaCount);
}
if ( SUCCEEDED( hr ) )
{
hr = pPro->get_MultipleBitrate(&vbMultiBitrate);
}
break;
}
}
// Start the encoding process.
if ( SUCCEEDED( hr ) )
{
hr = pEncoder->Start();
}
// Release pointers.
if ( pSrcGrpColl )
{
pSrcGrpColl->Release();
pSrcGrpColl = NULL;
}
if ( pSrcGrp )
{
pSrcGrp->Release();
pSrcGrp = NULL;
}
if ( pAudSrc )
{
pAudSrc->Release();
pAudSrc = NULL;
}
if ( pVidSrc )
{
pVidSrc->Release();
pVidSrc = NULL;
}
if ( pProColl )
{
pProColl->Release();
pProColl = NULL;
}
if ( pPro )
{
pPro->Release();
pPro = NULL;
}
if ( pPostview )
{
pPostview->Release();
pPostview = NULL;
}
if ( pPostColl )
{
pPostColl->Release();
pPostColl = NULL;
}
if ( pPostViewColl )
{
pPostViewColl->Release();
pPostViewColl = NULL;
}
if ( pEncoder )
{
pEncoder->Release();
pEncoder = NULL;
}
Requirements
Header: wmencode.h
Library: wmenc.exe
See Also
.gif)