コード例 #1
0
        /// <summary>
        /// Configs the asf.
        /// </summary>
        /// <param name="capGraph">The cap graph.</param>
        /// <param name="szOutputFileName">Name of the sz output file.</param>
        /// <returns></returns>
        private IBaseFilter ConfigAsf(ICaptureGraphBuilder2 capGraph, string szOutputFileName)
        {
            IBaseFilter       asfWriter        = null;
            IFileSinkFilter   pTmpSink         = null;
            IWMProfileManager ppProfileManager = null;
            IWMProfile        ppProfile        = null;

            try
            {
                WindowsMediaLib.WMUtils.WMCreateProfileManager(out ppProfileManager);
                string prx = File.ReadAllText(Path.Combine(Path.GetDirectoryName(
                                                               Assembly.GetEntryAssembly().Location), "profile.prx"));
                ppProfileManager.LoadProfileByData(prx, out ppProfile);

                int hr = capGraph.SetOutputFileName(MediaSubType.Asf, szOutputFileName, out asfWriter, out pTmpSink);
                Marshal.ThrowExceptionForHR(hr);

                WindowsMediaLib.IConfigAsfWriter lConfig = asfWriter as WindowsMediaLib.IConfigAsfWriter;
                lConfig.ConfigureFilterUsingProfile(ppProfile);
            }
            finally
            {
                Marshal.ReleaseComObject(pTmpSink);
                Marshal.ReleaseComObject(ppProfile);
                Marshal.ReleaseComObject(ppProfileManager);
            }

            return(asfWriter);
        }
コード例 #2
0
ファイル: StandardFilters.cs プロジェクト: Yitzchok/Splicer
        public static IBaseFilter RenderAsfWriterWithProfile(DisposalCleanup dc, IGraphBuilder graph, string profileData,
                                                             string outputFile)
        {
            int hr = 0;

            IBaseFilter asfWriterFilter = (IBaseFilter) new WMAsfWriter();

            dc.Add(asfWriterFilter);
            hr = graph.AddFilter(asfWriterFilter, "ASF Writer");
            DsError.ThrowExceptionForHR(hr);

            // Create an appropriate IWMProfile from the data
            IWMProfileManager profileManager = ProfileManager.CreateInstance();

            dc.Add(profileManager);

            IntPtr wmProfile = profileManager.LoadProfileByData(profileData);

            dc.Add(wmProfile);

            // Set the profile on the writer
            IConfigAsfWriter2 configWriter = (IConfigAsfWriter2)asfWriterFilter;

            configWriter.ConfigureFilterUsingProfile(wmProfile);

            hr = ((IFileSinkFilter)asfWriterFilter).SetFileName(outputFile, null);
            DsError.ThrowExceptionForHR(hr);

            return(asfWriterFilter);
        }
コード例 #3
0
        /// <summary>
        /// Load a PRX file as a profile
        /// </summary>
        /// <param name="prxFile"></param>
        /// <returns></returns>
        private IWMProfile LoadCustomProfile(String prxFile)
        {
            IWMProfile   pr;
            StreamReader stream;

            try
            {
                stream = new StreamReader(prxFile);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Failed to open profile file: " + e.ToString());
                return(null);
            }
            String s = stream.ReadToEnd();

            try
            {
                IntPtr file = Marshal.StringToCoTaskMemUni(s);
                profileManager.LoadProfileByData(file, out pr);
                Marshal.FreeCoTaskMem(file);
            }
            catch (Exception e)
            {
                eventLog.WriteEntry("Failed to load custom profile: " + e.ToString(), EventLogEntryType.Error, 1000);
                Debug.WriteLine("Failed to load custom profile: " + e.ToString());
                return(null);
            }
            return(pr);
        }
コード例 #4
0
ファイル: StandardFilters.cs プロジェクト: sandeshp/Splicer
        public static IBaseFilter RenderAsfWriterWithProfile(DisposalCleanup dc, IGraphBuilder graph, string profileData,
                                                             string outputFile)
        {
            if (dc == null)
            {
                throw new ArgumentNullException("dc");
            }
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }
            if (string.IsNullOrEmpty(profileData))
            {
                throw new ArgumentNullException("profileData");
            }
            if (string.IsNullOrEmpty(outputFile))
            {
                throw new ArgumentNullException("outputFile");
            }

            int hr = 0;

            var asfWriterFilter = (IBaseFilter) new WMAsfWriter();

            dc.Add(asfWriterFilter);
            hr = graph.AddFilter(asfWriterFilter, Resources.DefaultAsfWriterName);
            DsError.ThrowExceptionForHR(hr);

            // Create an appropriate IWMProfile from the data
            IWMProfileManager profileManager = ProfileManager.CreateInstance();

            dc.Add(profileManager);

            IntPtr wmProfile = profileManager.LoadProfileByData(profileData);

            dc.Add(wmProfile);

            // Set the profile on the writer
            var configWriter = (IConfigAsfWriter2)asfWriterFilter;

            configWriter.ConfigureFilterUsingProfile(wmProfile);

            hr = ((IFileSinkFilter)asfWriterFilter).SetFileName(outputFile, null);
            DsError.ThrowExceptionForHR(hr);

            return(asfWriterFilter);
        }
コード例 #5
0
        /// <summary>Do the conversion from DVR-MS to WAV.</summary>
        /// <returns>Null; ignored.</returns>
        protected override object DoWork()
        {
            // Get the filter graph
            object filterGraph = ClassId.CoCreateInstance(ClassId.FilterGraph);

            DisposalCleanup.Add(filterGraph);
            IGraphBuilder graph = (IGraphBuilder)filterGraph;

            // Add the ASF writer and set the output name
            IBaseFilter asfWriterFilter = (IBaseFilter)ClassId.CoCreateInstance(ClassId.WMAsfWriter);

            DisposalCleanup.Add(asfWriterFilter);
            graph.AddFilter(asfWriterFilter, null);
            IFileSinkFilter sinkFilter = (IFileSinkFilter)asfWriterFilter;

            sinkFilter.SetFileName(OutputFilePath, null);

            // Set the profile to be used for conversion
            if (_profilePath != null && _profilePath.Trim().Length > 0)
            {
                // Load the profile XML contents
                string profileData;
                using (StreamReader reader = new StreamReader(File.OpenRead(_profilePath)))
                {
                    profileData = reader.ReadToEnd();
                }

                // Create an appropriate IWMProfile from the data
                IWMProfileManager profileManager = ProfileManager.CreateInstance();
                DisposalCleanup.Add(profileManager);
                IntPtr wmProfile = profileManager.LoadProfileByData(profileData);
                DisposalCleanup.Add(wmProfile);

                // Set the profile on the writer
                IConfigAsfWriter2 configWriter = (IConfigAsfWriter2)asfWriterFilter;
                configWriter.ConfigureFilterUsingProfile(wmProfile);
            }

            // Add the source filter; should connect automatically through the appropriate transform filters
            graph.RenderFile(InputFilePath, null);

            // Run the graph to completion
            RunGraph(graph, asfWriterFilter);

            return(null);
        }
コード例 #6
0
        private void TestLoadID()
        {
            int        i = 3;
            IWMProfile pProfile, pProfile2;
            // 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);

            m_pWMProfileManager.LoadProfileByID(guidProfileID, out pProfile);

            m_pWMProfileManager.SaveProfile(pProfile, null, ref i);
            Debug.Assert(i > 0);
            StringBuilder sb = new StringBuilder(i);

            m_pWMProfileManager.SaveProfile(pProfile, sb, ref i);
            Debug.Assert(sb.Length > 0);

            m_pWMProfileManager.LoadProfileByData(sb.ToString(), out pProfile2);
            Debug.Assert(pProfile2 != null);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        /// <summary>
        /// Get asf profile information
        /// </summary>
        /// <returns></returns>
        public bool GetProfileFormatInfo(AsfFormatSelection avformat)
        {
            IWMProfileManager profileManager = null;
            IWMProfile        profile        = null;

            if (InnerList.Count > 0)
            {
                // Profile information already loaded
                return(true);
            }

#if DEBUG
            Debug.WriteLine("Look for Windows Media profile information: " + avformat);
#endif
            try
            {
                IWMProfileManager2        profileManager2;
                IWMProfileManagerLanguage profileManagerLanguage;
                int   nbrProfiles;
                int   totalItems = 0;
                short langID;

                // Open the profile manager
                var hr = WMLib.WMCreateProfileManager(out profileManager);
                if (hr >= 0)
                {
                    // Convert pWMProfileManager to a IWMProfileManager2
                    profileManager2        = profileManager as IWMProfileManager2;
                    profileManagerLanguage = (IWMProfileManagerLanguage)profileManager;

                    profileManager2.GetSystemProfileVersion(out var wmversion);
#if DEBUG
                    Debug.WriteLine("WM version=" + wmversion);
#endif

                    profileManagerLanguage.GetUserLanguageID(out langID);
#if DEBUG
                    Debug.WriteLine("WM language ID=" + langID);
#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);
#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;
                        if (profile2 != null)
                        {
                            hr = profile2.GetProfileID(out guid);
                        }
#if DEBUG
                        if (hr < 0)
                        {
                            Debug.WriteLine("GetProfileID failed for item " + p);
                        }
#endif
                    }
#if DEBUG
                    else
                    {
                        Debug.WriteLine("LoadSystemProfile failed for item " + p);
                    }
#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   = Directory.GetCurrentDirectory();
                string filterProfile = "*.prx";

                // Obtain the file system entries in the directory path.
                string[] directoryEntries =
                    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);
        }