Exemple #1
0
        /**
         * Constructor.
         */
        public Encoder()
        {
            this.enableRecording = false;
            this.chopNumber      = 0;
            this.chopLength      = -1;

            this.choppingTimer                = new System.Timers.Timer();
            this.choppingTimer.Elapsed       += this.OnRecordTimeElapsed;
            this.archiveState                 = WMENC_ARCHIVE_STATE.WMENC_ARCHIVE_STOPPED;
            this.stateChangeWaitHandle        = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, string.Empty);
            this.archiveStateChangeWaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, string.Empty);

            // Audio and video sources
            this.audioSource = null;
            this.videoSource = null;

            // Windows Media Encoder
            this.wmEncoder        = new WMEncoderClass();
            this.sourceGroup      = (IWMEncSourceGroup2)this.wmEncoder.SourceGroupCollection.Add("SG_1");
            this.wmEncoderProfile = new WMEncProfile2();

            // For now, we only listen these events
            this.wmEncoder.OnStateChange        += this.OnStateChange;
            this.wmEncoder.OnError              += this.OnError;
            this.wmEncoder.OnArchiveStateChange += this.OnArchiveStateChange;

            // Set recording props.
            this.wmEncoder.EnableAutoArchive = false;
            this.wmEncoder.AutoIndex         = false;

            // Set default profile values
            this.wmEncoderProfile.ValidateMode = true;
            this.wmEncoderProfile.ProfileName  = "Windows Media Encoder Profile";
            this.wmEncoderProfile.ContentType  = 17;                                        // Audio + Video
            this.wmEncoderAudience             = this.wmEncoderProfile.AddAudience(100000); // Initial bitrate = 100 kbps, will change automatically
            // when user sets video and audio params.
        }
Exemple #2
0
        /**
         * Constructor.
         */
        public Encoder()
        {
            this.enableRecording = false;
            this.chopNumber = 0;
            this.chopLength = -1;

            this.choppingTimer = new System.Timers.Timer();
            this.choppingTimer.Elapsed += this.OnRecordTimeElapsed;
            this.archiveState = WMENC_ARCHIVE_STATE.WMENC_ARCHIVE_STOPPED;
            this.stateChangeWaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, string.Empty);
            this.archiveStateChangeWaitHandle = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset, string.Empty);

            // Audio and video sources
            this.audioSource = null;
            this.videoSource = null;

            // Windows Media Encoder
            this.wmEncoder = new WMEncoderClass();
            this.sourceGroup = (IWMEncSourceGroup2)this.wmEncoder.SourceGroupCollection.Add("SG_1");
            this.wmEncoderProfile = new WMEncProfile2();

            // For now, we only listen these events
            this.wmEncoder.OnStateChange += this.OnStateChange;
            this.wmEncoder.OnError += this.OnError;
            this.wmEncoder.OnArchiveStateChange += this.OnArchiveStateChange;

            // Set recording props.
            this.wmEncoder.EnableAutoArchive = false;
            this.wmEncoder.AutoIndex = false;

            // Set default profile values
            this.wmEncoderProfile.ValidateMode = true;
            this.wmEncoderProfile.ProfileName = "Windows Media Encoder Profile";
            this.wmEncoderProfile.ContentType = 17; // Audio + Video
            this.wmEncoderAudience = this.wmEncoderProfile.AddAudience(100000); // Initial bitrate = 100 kbps, will change automatically
            // when user sets video and audio params.
        }
        public override Hashtable GetProfileInfos()
        {
            // 先清空
            profileInfos.Clear();

            // 声明必要变量
            IWMEncSourcePluginInfoManager sourceGroupCollection = encoder.SourcePluginInfoManager;
            IWMEncProfileCollection       profileCollection     = encoder.ProfileCollection;
            IWMEncProfile2 profile2 = new WMEncProfile2Class();

            // 刷新
            sourceGroupCollection.Refresh();

            // 将所有压缩方式的相关信息 依次存入 profileInfos(Hashtable)。
            for (int i = 0; i < profileCollection.Count; i++)
            {
                // 利用wp2获取压缩方式的相关信息
                profile2.LoadFromIWMProfile((IWMEncProfile)profileCollection.Item(i));

                // 获取压缩方式的相关描述
                StringBuilder profileInfo = new StringBuilder();
                profileInfo.AppendLine(profileCollection.Item(i).Description);
                for (int j = 0; j < profile2.AudienceCount; j++)
                {
                    IWMEncAudienceObj audienceObj = profile2.get_Audience(j);
                    // 假如此听众处于被选中状态
                    if (audienceObj.Selected)
                    {
                        object audioCodecName = null;
                        object videoCodecName = null;
                        try
                        {
                            // 得到音频编码名称
                            int audioCodecIndex = audienceObj.get_AudioCodec(0);
                            profile2.EnumAudioCodec(audioCodecIndex, out audioCodecName);

                            // 得到视频编码名称
                            int videoCodecIndex = audienceObj.get_VideoCodec(0);
                            profile2.EnumVideoCodec(videoCodecIndex, out videoCodecName);
                        }
                        catch
                        {
                        }

                        // 假如音频编码名称不为NULL
                        if (audioCodecName != null)
                        {
                            profileInfo.AppendLine("音频编码:" + audioCodecName.ToString());
                        }

                        // // 假如频编码名称不为NULL
                        if (videoCodecName != null)
                        {
                            profileInfo.AppendLine("视频编码:" + videoCodecName.ToString());
                            profileInfo.AppendLine("视频高度:" + Convert.ToString(audienceObj.get_VideoHeight(0)) + "\t视频宽度:" + Convert.ToString(audienceObj.get_VideoWidth(0)));
                        }
                    }
                }

                profileInfos.Add(profileCollection.Item(i).Name, profileInfo.ToString());
            }

            return(profileInfos);
        }