/// <summary>
 /// 开始编码
 /// </summary>
 /// <param name="mediaInfo">目标文件的相关信息</param>
 /// <param name="area">欲录制的屏幕的区域</param>
 internal abstract void Start(MediaInfo mediaInfo, ScreenArea area);
        /// <summary>
        /// 开始录制
        /// </summary>
        /// <param name="mediaInfo"></param>
        /// <param name="captureArea">捕获区域(录制的区域)</param>
        internal override void Start(MediaInfo mediaInfo, ScreenArea captureArea)
        {
            // 设置一些必要的变量
            IWMEncSourceGroupCollection sourceGroupCollection;
            IWMEncSourceGroup2          sourceGroup;
            IWMEncAudioSource           audioSource;
            IWMEncVideoSource2          vedioSource;

            //IWMEncProfile2 Pro;

            sourceGroupCollection = encoder.SourceGroupCollection;
            sourceGroup           = (IWMEncSourceGroup2)sourceGroupCollection.Add("SG_1");

            // 假如 是仅音频,或者是 音频视频 全有,则添加音频设备,并进行相关设置
            if (mediaInfo.AudioVedio == AudioVedioType.AudioOnly || mediaInfo.AudioVedio == AudioVedioType.Both)
            {
                audioSource = (IWMEncAudioSource)sourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
                audioSource.SetInput("Default_Audio_Device", "DEVICE", "");
            }

            // 假如 是仅视频,或者是 音频视频 全有,则添加视频设备
            if (mediaInfo.AudioVedio == AudioVedioType.VedioOnly || mediaInfo.AudioVedio == AudioVedioType.Both)
            {
                vedioSource = (IWMEncVideoSource2)sourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
                vedioSource.SetInput("ScreenCapture1", "ScreenCap", "");

                // 视频尺寸/显示器尺寸  缩放比
                Size  screenSize = SystemInformation.PrimaryMonitorSize;
                float scaleX     = (float)vedioSource.Height / (float)screenSize.Height;
                float scaleY     = (float)vedioSource.Width / (float)screenSize.Width;

                // 设置左边和上部剪裁区
                vedioSource.CroppingLeftMargin = (int)((float)captureArea.X * scaleY);
                vedioSource.CroppingTopMargin  = (int)((float)captureArea.Y * scaleX);

                // 设置右边和下部剪裁区
                int bottomMargin = screenSize.Height - captureArea.Height - captureArea.Y;
                int rightMargin  = screenSize.Width - captureArea.Weight - captureArea.X;
                vedioSource.CroppingRightMargin  = (int)((float)bottomMargin * scaleY);
                vedioSource.CroppingBottomMargin = (int)((float)rightMargin * scaleX);
            }

            // 设置压缩方式
            // 首先必须刷新一下信息
            IWMEncSourcePluginInfoManager sourcePluginInfoManager = encoder.SourcePluginInfoManager;

            sourcePluginInfoManager.Refresh();
            IWMEncProfileCollection wpfc = encoder.ProfileCollection;

            // 将压缩方式的名称添加进 profileNames 变量,将压缩方式对象本身添加到profiles 变量
            for (int i = 0; i < wpfc.Count; i++)
            {
                if (mediaInfo.ProfileName == wpfc.Item(i).Name)
                {
                    sourceGroup.set_Profile(wpfc.Item(i));
                    break;
                }
            }

            // 设置存放位置
            encoder.File.LocalFileName = mediaInfo.SavePath;

            // 启动
            encoder.Start();
        }
Пример #3
0
 public void Start(MediaInfo mediaInfo, ScreenArea area)
 {
     _encoder.Start(mediaInfo, area);
 }