Tosh
Joined: 02 Jan 2006
Posts: 1
|
Posted:
Mon Jan 02, 2006 1:57 pm Post subject:
Writing asf file , Help needed |
|
|
Hi, i'm trying to wrtite an asf file, but the sdk is a bit confusing to me.
Her what i'm doing before writing :
| Code: |
if (m_pWriter)
{
SAFE_RELEASE(m_pWriter);
}
HRESULT hr = WMCreateWriter(0, &m_pWriter);
if (FAILED(hr))
{
return false;
}
hr = m_pWriter->SetOutputFilename(szFileName);
if (FAILED(hr))
{
return false;
}
// =====================================================================
// Profile creation
// =====================================================================
IWMProfile* pProfile = 0;
IWMProfileManager* pProfileMan = 0;
IWMMediaProps* pMediaProps = 0;
IWMStreamConfig* pStreamConfig = 0;
if (FAILED(hr = WMCreateProfileManager(&pProfileMan)))
{
return false;
}
if (!CreatProfile(pProfileMan, &pProfile))
{
return false;
}
// =====================================================================
// Customize profile
// =====================================================================
hr = pProfile->CreateNewStream(WMMEDIATYPE_Video, &pStreamConfig);
hr = pStreamConfig->SetStreamNumber(1);
hr = pStreamConfig->SetStreamName(L"Stream Name");
hr = pStreamConfig->SetConnectionName(L"Connection Name");
hr = pStreamConfig->SetBufferWindow(-1);
hr = pStreamConfig->SetBitrate(193000);
hr = pStreamConfig->QueryInterface( IID_IWMMediaProps, (void**)&pMediaProps);
WM_MEDIA_TYPE MediaType;
WMVIDEOINFOHEADER vihVideoInfo;
WMVIDEOINFOHEADER videoInfo;
videoInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
videoInfo.bmiHeader.biCompression = CLXProcessing::m_sdwYUY2;
videoInfo.bmiHeader.biBitCount = 16;
videoInfo.bmiHeader.biWidth = 720;
videoInfo.bmiHeader.biHeight = 576;
videoInfo.bmiHeader.biPlanes = 1;
DWORD lStride = (videoInfo.bmiHeader.biWidth * (videoInfo.bmiHeader.biBitCount / 8) + 3) & ~3;
videoInfo.bmiHeader.biSizeImage = videoInfo.bmiHeader.biHeight * lStride;;
videoInfo.bmiHeader.biClrImportant = 0;
videoInfo.rcSource.left = 0;
videoInfo.rcSource.top = 0;
videoInfo.rcSource.right = videoInfo.bmiHeader.biWidth;
videoInfo.rcSource.bottom = videoInfo.bmiHeader.biHeight;
videoInfo.rcTarget = videoInfo.rcSource;
videoInfo.dwBitRate = 193000;
videoInfo.dwBitErrorRate = 0;
videoInfo.AvgTimePerFrame = 666666;
MediaType.majortype = WMMEDIATYPE_Video;
MediaType.subtype = WMMEDIASUBTYPE_YUY2;
MediaType.bFixedSizeSamples = TRUE;
MediaType.bTemporalCompression = FALSE;
MediaType.lSampleSize = 0;
MediaType.formattype = WMFORMAT_VideoInfo;
MediaType.pUnk = 0;
MediaType.cbFormat = sizeof(WMVIDEOINFOHEADER);
MediaType.pbFormat = (BYTE*)&videoInfo;
MediaType.lSampleSize = 0;
if (FAILED(pMediaProps->SetMediaType(&MediaType)))
{
return false;
}
if (FAILED(hr = pProfile->AddStream(pStreamConfig)))
{
return false;
}
// =====================================================================
// Assign Profile
// =====================================================================
if (FAILED(hr = m_pWriter->SetProfile(pProfile)))
{
return false;
}
// =====================================================================
// Begin Writing
// =====================================================================
hr = m_pWriter->BeginWriting(); |
Next i'm trrying to fill the writer, but a the seconde frame it failed due to invalid data.
My question are :
What i'm doing wrong, why does it work on first frame and failed on the next one...
Video date a presented to me as YUY2 16 (720 * 576) format.
Thanks, it comes to be a nightmare for me...
|
|