static void test_profile_manager_interfaces(void) { HRESULT hr; IWMProfileManager *profile; hr = WMCreateProfileManager(&profile); ok(hr == S_OK, "WMCreateProfileManager failed 0x%08x\n", hr); if(FAILED(hr)) { win_skip("Failed to create IWMProfileManager\n"); return; } IWMProfileManager_Release(profile); }
HRESULT CProfile::CreateNew(void) { HRESULT hr = S_OK; CComPtr <IWMProfileManager> pIWMProfileManager; hr = WMCreateProfileManager(&pIWMProfileManager); if(FAILED(hr) || pIWMProfileManager == NULL) return hr; // create empty profile with current version hr = pIWMProfileManager->CreateEmptyProfile(WMT_VER_9_0, &m_pIWMProfile); if (FAILED(hr)) { hr = pIWMProfileManager->CreateEmptyProfile(WMT_VER_8_0, &m_pIWMProfile); if (FAILED(hr)) { hr = pIWMProfileManager->CreateEmptyProfile(WMT_VER_7_0, &m_pIWMProfile); if (FAILED(hr)) return hr; } } // set name and description hr = m_pIWMProfile->SetName(m_strName); _ASSERT(!FAILED(hr)); hr = m_pIWMProfile->SetDescription(m_strDescription); _ASSERT(!FAILED(hr)); if (m_bHasAudio) { hr = m_AudioStream.CreateNew(m_pIWMProfile); if (FAILED(hr)) return hr; } if (m_bHasVideo) { m_VideoStream.SetBestVideoCodec(m_nBestVideoCodec); hr = m_VideoStream.CreateNew(m_pIWMProfile); if (FAILED(hr)) return hr; } return S_OK; }
bool createFileCaptureFilter (const File& file, int quality) { removeFileCaptureFilter(); file.deleteFile(); mediaControl->Stop(); firstRecordedTime = Time(); recordNextFrameTime = true; previewMaxFPS = 60; HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter); if (SUCCEEDED (hr)) { ComSmartPtr <IFileSinkFilter> fileSink; hr = asfWriter.QueryInterface (fileSink); if (SUCCEEDED (hr)) { hr = fileSink->SetFileName (file.getFullPathName().toWideCharPointer(), 0); if (SUCCEEDED (hr)) { hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter")); if (SUCCEEDED (hr)) { ComSmartPtr <IConfigAsfWriter> asfConfig; hr = asfWriter.QueryInterface (asfConfig); asfConfig->SetIndexMode (true); ComSmartPtr <IWMProfileManager> profileManager; hr = WMCreateProfileManager (profileManager.resetAndGetPointerAddress()); // This gibberish is the DirectShow profile for a video-only wmv file. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\">" "<streamconfig majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" " "streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" " "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\">" "<videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>" "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" " "btemporalcompression=\"1\" lsamplesize=\"0\">" "<videoinfoheader dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"$AVGTIMEPERFRAME\">" "<rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/>" "<rctarget left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/>" "<bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" " "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" " "biclrused=\"0\" biclrimportant=\"0\"/>" "</videoinfoheader>" "</wmmediatype>" "</streamconfig>" "</profile>"); const int fps[] = { 10, 15, 30 }; int maxFramesPerSecond = fps [jlimit (0, numElementsInArray (fps) - 1, quality & 0xff)]; if ((quality & 0xff000000) != 0) // (internal hacky way to pass explicit frame rates for testing) maxFramesPerSecond = (quality >> 24) & 0xff; prof = prof.replace ("$WIDTH", String (width)) .replace ("$HEIGHT", String (height)) .replace ("$AVGTIMEPERFRAME", String (10000000 / maxFramesPerSecond)); ComSmartPtr <IWMProfile> currentProfile; hr = profileManager->LoadProfileByData (prof.toWideCharPointer(), currentProfile.resetAndGetPointerAddress()); hr = asfConfig->ConfigureFilterUsingProfile (currentProfile); if (SUCCEEDED (hr)) { ComSmartPtr <IPin> asfWriterInputPin; if (getPin (asfWriter, PINDIR_INPUT, asfWriterInputPin, "Video Input 01")) { hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin); if (SUCCEEDED (hr) && ok && activeUsers > 0 && SUCCEEDED (mediaControl->Run())) { previewMaxFPS = (quality < 2) ? 15 : 25; // throttle back the preview comps to try to leave the cpu free for encoding if ((quality & 0x00ff0000) != 0) // (internal hacky way to pass explicit frame rates for testing) previewMaxFPS = (quality >> 16) & 0xff; return true; } } } } } }
bool UBWindowsMediaFile::init(const QString& videoFileName, const QString& profileData, int pFramesPerSecond , int pixelWidth, int pixelHeight, int bitsPerPixel) { mFramesPerSecond = pFramesPerSecond; mVideoFileName = videoFileName; CoInitialize(0); if (FAILED(WMCreateProfileManager(&mWMProfileManager))) { setLastErrorMessage("Unable to create a WMProfileManager"); close(); return false; } IWMProfileManager2 *wmProfileManager = 0; if (FAILED(mWMProfileManager->QueryInterface(IID_IWMProfileManager2, (void**) &wmProfileManager))) { setLastErrorMessage("Unable to query the WMProfileManager for interface WMProfileManager2"); close(); return false; } HRESULT hr = wmProfileManager->SetSystemProfileVersion(WMT_VER_9_0); wmProfileManager->Release(); if (FAILED(hr)) { setLastErrorMessage("Unable to set WMProfileManager SystemProfileVersion"); close(); return false; } if (FAILED(mWMProfileManager->LoadProfileByData((LPCTSTR) profileData.utf16(), &mWMProfile))) { setLastErrorMessage("Unable to load WMProfileManager custom profile"); close(); return false; } DWORD streamCount = -1; if (FAILED(mWMProfile->GetStreamCount(&streamCount))) { setLastErrorMessage("Unable to read mWMProfile stream count"); close(); return false; } if (FAILED(WMCreateWriter(NULL, &mWMWriter))) { setLastErrorMessage("Unable to create WMMediaWriter Object"); close(); return false; } if (FAILED(mWMWriter->SetProfile(mWMProfile))) { setLastErrorMessage("Unable to set WMWriter system profile"); close(); return false; } DWORD mediaInputCount = 0; if (FAILED(mWMWriter->GetInputCount(&mediaInputCount))) { setLastErrorMessage("Unable to get input count for profile"); close(); return false; } for (DWORD i = 0; i < mediaInputCount; i++) { IWMInputMediaProps* wmInoutMediaProps = 0; if (FAILED(mWMWriter->GetInputProps(i, &wmInoutMediaProps))) { setLastErrorMessage("Unable to get WMWriter input properties"); close(); return false; } GUID guidInputType; if (FAILED(wmInoutMediaProps->GetType(&guidInputType))) { setLastErrorMessage("Unable to get WMWriter input property type"); close(); return false; } if (guidInputType == WMMEDIATYPE_Video) { mWMInputVideoProps = wmInoutMediaProps; mVideoInputIndex = i; } else if (guidInputType == WMMEDIATYPE_Audio) { mWMInputAudioProps = wmInoutMediaProps; mAudioInputIndex = i; } else { wmInoutMediaProps->Release(); wmInoutMediaProps = 0; } } if (mWMInputVideoProps == 0) { setLastErrorMessage("Profile does not accept video input"); close(); return false; } if (mWMInputAudioProps == 0) { setLastErrorMessage("Profile does not accept audio input"); close(); return false; } if (FAILED(mWMWriter->SetOutputFilename((LPCTSTR) videoFileName.utf16()))) { setLastErrorMessage("Unable to set the output filename"); close(); return false; } if(!initVideoStream(pixelWidth, pixelHeight, bitsPerPixel)) { close(); return false; } if (FAILED(mWMWriter->BeginWriting())) { setLastErrorMessage("Unable to initialize video frame writing"); return false; } return true; }