private void Config() { IWMWriter pWMWriter; IWMProfileManager pWMProfileManager = null; IWMProfile pWMProfile = null; INSSBuffer pSample; // Profile id for "Windows Media Video 8 for Dial-up Modem (No audio, 56 Kbps)" Guid guidProfileID = new Guid(0x6E2A6955, 0x81DF, 0x4943, 0xBA, 0x50, 0x68, 0xA9, 0x86, 0xA7, 0x08, 0xF6); WMUtils.WMCreateProfileManager(out pWMProfileManager); IWMProfileManager2 pProfileManager2 = (IWMProfileManager2)pWMProfileManager; pProfileManager2.SetSystemProfileVersion(WMVersion.V8_0); pProfileManager2.LoadProfileByID(guidProfileID, out pWMProfile); WMUtils.WMCreateWriter(IntPtr.Zero, out pWMWriter); pWMWriter.SetProfile(pWMProfile); pWMWriter.SetOutputFilename("foo.out"); Marshal.ReleaseComObject(pWMProfile); Marshal.ReleaseComObject(pWMProfileManager); pWMWriter.BeginWriting(); pWMWriter.AllocateSample(MAXLENGTH, out pSample); m_pSample = (INSSBuffer3)pSample; }
private void TestVersion() { WMVersion v; m_pWMProfileManager2.SetSystemProfileVersion(WMVersion.V7_0); m_pWMProfileManager2.GetSystemProfileVersion(out v); Debug.Assert(v == WMVersion.V7_0); }
private void Config() { IWMProfileManager pWMProfileManager; WMUtils.WMCreateProfileManager(out pWMProfileManager); IWMProfileManager2 pProfileManager2 = (IWMProfileManager2)pWMProfileManager; pProfileManager2.SetSystemProfileVersion(WMVersion.V8_0); pProfileManager2.CreateEmptyProfile(WMVersion.V8_0, out m_pProfile); }
private void Config() { IWMProfileManager profileManager; WMUtils.WMCreateProfileManager(out profileManager); IWMProfileManager2 profMan2 = (IWMProfileManager2)profileManager; profMan2.SetSystemProfileVersion(WMVersion.V9_0); m_pCodecInfo = (IWMCodecInfo3)profileManager; }
private void Config() { IWMProfileManager pWMProfileManager; IWMProfile pProfile; WMUtils.WMCreateProfileManager(out pWMProfileManager); IWMProfileManager2 pProfileManager2 = (IWMProfileManager2)pWMProfileManager; pProfileManager2.SetSystemProfileVersion(WMVersion.V8_0); pProfileManager2.CreateEmptyProfile(WMVersion.V8_0, out pProfile); m_pLang = pProfile as IWMLanguageList; }
private void Config() { IWMProfileManager pWMProfileManager; IWMProfile pProfile; WMUtils.WMCreateProfileManager(out pWMProfileManager); IWMProfileManager2 pProfileManager2 = (IWMProfileManager2)pWMProfileManager; pProfileManager2.SetSystemProfileVersion(WMVersion.V8_0); pProfileManager2.LoadProfileByID(guidProfileID, out pProfile); m_pProfile2 = (IWMProfile2)pProfile; }
private void Config() { IWMProfileManager pWMProfileManager; IWMProfile pProfile; Guid guidProfileID = new Guid("{5B16E74B-4068-45B5-B80E-7BF8C80D2C2F}"); WMUtils.WMCreateProfileManager(out pWMProfileManager); IWMProfileManager2 pProfileManager2 = (IWMProfileManager2)pWMProfileManager; pProfileManager2.SetSystemProfileVersion(WMVersion.V8_0); pProfileManager2.LoadProfileByID(guidProfileID, out pProfile); m_pProfile3 = (IWMProfile3)pProfile; }
private void TestSystem() { // GetSystemProfileCount & LoadSystemProfile only work if the profile version // is set to v8. But the version can only be set by using IWMProfileManager2. Go figure. int i; IWMProfile pProfile; IWMProfileManager2 pWMProfileManager2 = (IWMProfileManager2)m_pWMProfileManager; pWMProfileManager2.SetSystemProfileVersion(WMVersion.V8_0); m_pWMProfileManager.GetSystemProfileCount(out i); Debug.Assert(i > 0); m_pWMProfileManager.LoadSystemProfile(13, out pProfile); Debug.Assert(pProfile != null); }
private IWMProfile CreateProfile() { IWMProfileManager pWMProfileManager = null; IWMProfile pWMProfile = null; // Open the profile manager WMUtils.WMCreateProfileManager(out pWMProfileManager); // Convert pWMProfileManager to a IWMProfileManager2 IWMProfileManager2 pProfileManager2 = (IWMProfileManager2)pWMProfileManager; // Specify the version number of the profiles to use pProfileManager2.SetSystemProfileVersion(WMVersion.V8_0); pProfileManager2.LoadProfileByID(g, out pWMProfile); return(pWMProfile); }
private void SetCutomProfile(int vidbitrate, int audbitrate, int vidheight, int vidwidth, double fps) { //seperate method atm braindump for adjusting an existing profile (prx file) //method call is not enabled yet IWMProfileManager profileManager = null; IWMProfileManager2 profileManager2 = null; IWMProfile profile = null; IWMStreamConfig streamConfig; //IWMInputMediaProps inputProps = null; IWMProfileManagerLanguage profileManagerLanguage = null; WMVersion wmversion = WMVersion.V8_0; int nbrProfiles = 0; short langID; StringBuilder profileName = new StringBuilder(MAXLENPROFNAME); StringBuilder profileDescription = new StringBuilder(MAXLENPROFDESC); int profileNameLen = MAXLENPROFNAME; int profileDescLen = MAXLENPROFDESC; profileName.Length = 0; profileDescription.Length = 0; double videoFps = fps; long singleFramePeriod = (long)((10000000L / fps)); //Guid guidInputType; //int dwInputCount = 0; int hr; int videoBitrate = vidbitrate; int audioBitrate = audbitrate; int videoHeight = vidheight; int videoWidth = vidwidth; double videofps = fps; int streamCount = 0; IWMMediaProps streamMediaProps = null; IntPtr mediaTypeBufferPtr = IntPtr.Zero; uint mediaTypeBufferSize = 0; Guid streamType = Guid.Empty; WmMediaType videoMediaType = new WmMediaType(); //Set WMVIDEOHEADER WMVIDEOINFOHEADER videoInfoHeader = new WMVIDEOINFOHEADER(); //Setup the profile manager hr = WMLib.WMCreateProfileManager(out profileManager); profileManager2 = (IWMProfileManager2)profileManager; //Set profile version - possibly not needed in this case. profileManager2.SetSystemProfileVersion(WMVersion.V8_0); //get the profile to modify string strprofileType = Config.GetFile(Config.Dir.Base, @"Profiles\MPCustom.prx"); //read the profile contents string profileContents = ""; using (StreamReader prx = new StreamReader(strprofileType)) { profileContents = prx.ReadToEnd(); } profileManager2 = profileManager as IWMProfileManager2; profileManagerLanguage = profileManager as IWMProfileManagerLanguage; hr = profileManager2.GetSystemProfileVersion(out wmversion); Log.Info("DVRMS2WMV: WM version=" + wmversion.ToString()); hr = profileManagerLanguage.GetUserLanguageID(out langID); Log.Info("DVRMS2WMV: WM language ID=" + langID.ToString()); hr = profileManager2.SetSystemProfileVersion(DefaultWMversion); hr = profileManager2.GetSystemProfileCount(out nbrProfiles); Log.Info("DVRMS2WMV: ProfileCount=" + nbrProfiles.ToString()); //load the profile contents hr = profileManager.LoadProfileByData(profileContents, out profile); //get the profile name hr = profile.GetName(profileName, ref profileNameLen); Log.Info("DVRMS2WMV: profile name {0}", profileName.ToString()); //get the profile description hr = profile.GetDescription(profileDescription, ref profileDescLen); Log.Info("DVRMS2WMV: profile description {0}", profileDescription.ToString()); //get the stream count hr = profile.GetStreamCount(out streamCount); for (int i = 0; i < streamCount; i++) { profile.GetStream(i, out streamConfig); streamMediaProps = (IWMMediaProps)streamConfig; streamConfig.GetStreamType(out streamType); if (streamType == MediaType.Video) { //adjust the video details based on the user input values. streamConfig.SetBitrate(videoBitrate); streamConfig.SetBufferWindow(-1); //3 or 5 seconds ??? streamMediaProps.GetMediaType(IntPtr.Zero, ref mediaTypeBufferSize); mediaTypeBufferPtr = Marshal.AllocHGlobal((int)mediaTypeBufferSize); streamMediaProps.GetMediaType(mediaTypeBufferPtr, ref mediaTypeBufferSize); Marshal.PtrToStructure(mediaTypeBufferPtr, videoMediaType); Marshal.FreeHGlobal(mediaTypeBufferPtr); Marshal.PtrToStructure(videoMediaType.pbFormat, videoInfoHeader); videoInfoHeader.TargetRect.right = 0; // set to zero to take source size videoInfoHeader.TargetRect.bottom = 0; // set to zero to take source size videoInfoHeader.BmiHeader.Width = videoWidth; videoInfoHeader.BmiHeader.Height = videoHeight; videoInfoHeader.BitRate = videoBitrate; videoInfoHeader.AvgTimePerFrame = singleFramePeriod; //Need to check how this is to be calculated IntPtr vidInfoPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WMVIDEOINFOHEADER))); Marshal.StructureToPtr(videoInfoHeader, vidInfoPtr, false); videoMediaType.pbFormat = vidInfoPtr; hr = streamMediaProps.SetMediaType(videoMediaType); Marshal.FreeHGlobal(vidInfoPtr); } if (streamType == MediaType.Audio) { //adjust the audio details based on the user input //audio is determined from bitrate selection and thus effects audio profile. hr = streamConfig.SetBitrate(audioBitrate); hr = streamConfig.SetBufferWindow(-1); //3 or 5 seconds ??? //TODO: set the WaveformatEx profile info etc } //recofigures the stream ready for saving hr = profile.ReconfigStream(streamConfig); } //save the profile //You should make two calls to SaveProfile. //On the first call, pass NULL as pwszProfile. int profileLength = 0; hr = profileManager2.SaveProfile(profile, null, ref profileLength); //On return, the value of pdwLength is set to the length required to hold the profile in string form. //TODO: set memory buffer to profileLength //Then you can allocate the required amount of memory for the buffer and pass a pointer to it as pwszProfile on the second call. hr = profileManager2.SaveProfile(profile, profileContents, ref profileLength); }
/// <summary> /// Create filename from specified profile using specified framerate /// </summary> /// <param name="lpszFileName">File name to create</param> /// <param name="guidProfileID">WM Profile to use for compression</param> /// <param name="iFrameRate">Frames Per Second</param> public CwmvFile(string lpszFileName, ref Guid guidProfileID, int iFrameRate) { Guid guidInputType; int dwInputCount; IWMProfileManager pWMProfileManager = null; IWMProfile pWMProfile = null; // Initialize all member variables m_iFrameRate = iFrameRate; m_dwVideoInput = -1; m_dwCurrentVideoSample = 0; m_msVideoTime = 0; m_pWMWriter = null; m_pInputProps = null; m_Init = false; try { // Open the profile manager WMUtils.WMCreateProfileManager(out pWMProfileManager); // Convert pWMProfileManager to a IWMProfileManager2 IWMProfileManager2 pProfileManager2 = (IWMProfileManager2)pWMProfileManager; // Specify the version number of the profiles to use pProfileManager2.SetSystemProfileVersion(WMVersion.V8_0); // Load the profile specified by the caller pProfileManager2.LoadProfileByID(guidProfileID, out pWMProfile); // Create a writer. This is the interface we actually write with WMUtils.WMCreateWriter(IntPtr.Zero, out m_pWMWriter); // Set the profile we got into the writer. This controls compression, video // size, # of video channels, # of audio channels, etc m_pWMWriter.SetProfile(pWMProfile); // Find out how many inputs are in the current profile m_pWMWriter.GetInputCount(out dwInputCount); // Assume we won't find any video pins m_dwVideoInput = -1; // Find the first video input on the writer for (int i = 0; i < dwInputCount; i++) { // Get the properties of channel #i m_pWMWriter.GetInputProps(i, out m_pInputProps); // Read the type of the channel m_pInputProps.GetType(out guidInputType); // If it is video, we are done if (guidInputType == MediaType.Video) { m_dwVideoInput = i; break; } } // Didn't find a video channel if (m_dwVideoInput == -1) { throw new Exception("Profile does not accept video input"); } // Specify the file name for the output m_pWMWriter.SetOutputFilename(lpszFileName); } catch { Close(); throw; } finally { // Release the locals if (pWMProfile != null) { Marshal.ReleaseComObject(pWMProfile); pWMProfile = null; } if (pWMProfileManager != null) { Marshal.ReleaseComObject(pWMProfileManager); pWMProfileManager = null; } } }
private bool Initialize(string destinationFileName, VideoQuality videoQuality) { IWMProfileManager profileManagerTemp = null; IWMProfile profile = null; int inputCount = 0; Guid inputTypeId; bool success = false; try { #region Initialize Properties CurrentSampleIndex = 0; CurrentSampleTimeStamp = 0; VideoChannelIndex = -1; MediaWriterConfigured = false; MediaWriterIsWriting = false; #endregion #region Create ProfileManager WMUtils.WMCreateProfileManager(out profileManagerTemp); IWMProfileManager2 profileManager = (IWMProfileManager2)profileManagerTemp; #endregion #region Configure ProfileManager profileManager.SetSystemProfileVersion(WMVersion.V8_0); #endregion #region Load Profile switch (videoQuality) { case VideoQuality.Kbps128: profileManager.LoadProfileByData(Wilke.Interactive.Drone.Control.Properties.Resources.VideoProfile128kbps, out profile); break; case VideoQuality.Kbps256: profileManager.LoadProfileByData(Wilke.Interactive.Drone.Control.Properties.Resources.VideoProfile256kbps, out profile); break; } #endregion #region Create Writer WMUtils.WMCreateWriter(IntPtr.Zero, out mediaWriter); #endregion #region Configure Writer MediaWriter.SetProfile(profile); MediaWriter.GetInputCount(out inputCount); // Find the first video input on the writer for (int index = 0; index < inputCount; index++) { // Get the properties of channel #index MediaWriter.GetInputProps(index, out mediaProperties); // Read the type of the channel MediaProperties.GetType(out inputTypeId); // If it is video, we are done if (inputTypeId == MediaType.Video) { VideoChannelIndex = index; break; } } // Didn't find a video channel if (VideoChannelIndex == -1) { throw new Exception("Profile does not accept video input"); } MediaWriter.SetOutputFilename(destinationFileName); #endregion success = true; } catch { throw; } return(success); }
/// <summary> /// Get asf profile information /// </summary> /// <returns></returns> public bool GetProfileFormatInfo(AsfFormatSelection avformat) { int hr; IWMProfileManager profileManager = null; IWMProfile profile = null; if (this.InnerList.Count > 0) { // Profile information already loaded return(true); } #if DEBUG Debug.WriteLine("Look for Windows Media profile information: " + avformat.ToString()); #endif try { IWMProfileManager2 profileManager2 = null; IWMProfileManagerLanguage profileManagerLanguage = null; WMVersion wmversion = WMVersion.V4_0; int nbrProfiles = 0; int totalItems = 0; short langID; // Open the profile manager try { hr = WMLib.WMCreateProfileManager(out profileManager); } catch (Exception) { hr = -1; } if (hr >= 0) { // Convert pWMProfileManager to a IWMProfileManager2 profileManager2 = profileManager as IWMProfileManager2; profileManagerLanguage = profileManager as IWMProfileManagerLanguage; hr = profileManager2.GetSystemProfileVersion(out wmversion); #if DEBUG Debug.WriteLine("WM version=" + wmversion.ToString()); #endif hr = profileManagerLanguage.GetUserLanguageID(out langID); #if DEBUG Debug.WriteLine("WM language ID=" + langID.ToString()); #endif //IWMProfileManagerLanguage // Specify the version number of the profiles to use hr = profileManager2.SetSystemProfileVersion(DefaultWMversion); // Marshal.ThrowExceptionForHR(hr); if (hr >= 0) { hr = profileManager2.GetSystemProfileCount(out nbrProfiles); if (hr < 0) { // No profiles available, so nothing to do return(false); } #if DEBUG Debug.WriteLine("ProfileCount=" + nbrProfiles.ToString()); #endif } else { // Error occured when setting profile version return(false); } } else { // Error occured when creating profile manager return(false); } // There are profiles to look for! for (int p = 0; (p < nbrProfiles) && (hr >= 0); p++) { Guid guid = Guid.Empty; // Load the profile specified by the caller //hr = profileManager2.LoadProfileByID(guid, out profile); // Marshal.ThrowExceptionForHR(hr); hr = profileManager2.LoadSystemProfile(p, out profile); if (hr >= 0) { IWMProfile2 profile2 = profile as IWMProfile2; hr = profile2.GetProfileID(out guid); #if DEBUG if (hr < 0) { Debug.WriteLine("GetProfileID failed for item " + p.ToString()); } #endif } #if DEBUG else { Debug.WriteLine("LoadSystemProfile failed for item " + p.ToString()); } #endif if (hr >= 0) { // Add item to list if (AddProfileItem(avformat, profile, guid, null)) { totalItems++; } } } // for p // Start of NEW // Look for profile (*.prx) files in the current directory. // If found, then add the profile(s) to the list string profileData; string pathProfile = System.IO.Directory.GetCurrentDirectory(); string filterProfile = "*.prx"; // Obtain the file system entries in the directory path. string[] directoryEntries = System.IO.Directory.GetFileSystemEntries(pathProfile, filterProfile); foreach (string filename in directoryEntries) { Debug.WriteLine(filename); if (GetProfileDataFromFile(filename, out profileData)) { hr = profileManager.LoadProfileByData(profileData, out profile); if (hr >= 0) { if (AddProfileItem(avformat, profile, Guid.Empty, filename)) { totalItems++; } } } } // End of NEW } finally { FindDefaultAsfItem(avformat); // Release the locals if (profile != null) { Marshal.ReleaseComObject(profile); profile = null; } if (profileManager != null) { Marshal.ReleaseComObject(profileManager); profileManager = null; } } return(false); }