I am trying to apply a CBR profile to an ASF Writer to reduce latency for a video/audio streaming.
This is what I've done till now:
- Using Media Encoder, I generated a default CBR profile
- Saved the profile to a prx file
Used this code to apply the profile to the ASF Writer:
// Initialize a new Profile Manager
IWMProfileManager* pIPM = 0;
WMCreateProfileManager(&pIPM);
FILE * file = fopen("lowprofile.prx", "rb");
fseek(file, 0, SEEK_END);
long length = ftell(file);
fseek(file, 0, SEEK_SET);
wchar_t * buffer = new wchar_t[length];
size_t numRead = fread(buffer, sizeof(wchar_t), length, file);
buffer[numRead] = NULL;
fclose(file);
IWMProfile* pProxProfile = 0;
hr = pIPM->LoadProfileByData(buffer, &pProxProfile);
// Set the profile for the writer
CComQIPtr<IConfigAsfWriter2> pConfigWriter;
pConfigWriter = m_pWMASFWritter;
hr = pConfigWriter->SetParam(AM_CONFIGASFWRITER_PARAM_DONTCOMPRESS, TRUE, 0);
hr = pConfigWriter->ConfigureFilterUsingProfile(pProxProfile); // THIS LINE FAILS, hr = E_FAIL
hr=m_pGraph->AddFilter(m_pWMASFWritter,L"ASF Writter");
if(FAILED(hr))
return FALSE;开发者_Go百科
//etc..
What's wrong with this code? I misunderstood something??
Unfortunately for me there's no code in the media format sdk nor available on the internet to help me applying such filter. I am trying to read carefully the documentation available on msdn, but it's surely not as clear as a good code sample.
Can someone give me a hint please?
That looks ok, I have code close to that working just fine - try and set the profile file to use standard audio/video codecs to see if the code works then just to pinpoint the problem and/or comment out the SetParam
call.
Also make sure you first add the AsfFileWriter to the graph, then configure it and finally connect the graph. You currently add it only after configuring it - again, that might work, it's just not the order I have running and definitely works.
Here you are calculating the filesize in bytes:
fseek(file, 0, SEEK_END);
long length = ftell(file);
fseek(file, 0, SEEK_SET);
But then you treat it as the size in chacacters:
wchar_t * buffer = new wchar_t[length];
size_t numRead = fread(buffer, sizeof(wchar_t), length, file);
buffer[numRead] = NULL;
You can use the following fix:
long length = ftell(file) / sizeof(wchar_t);
精彩评论