private bool SelectProfile(IWMEncSourceGroup SrcGrp) { string ProfileName = null; switch (m_CurrentProfile) { case EncodingProfileEnum.LOW: ProfileName = VbcLowProfile; break; case EncodingProfileEnum.HIGH: ProfileName = VbcHighProfile; break; case EncodingProfileEnum.LOSSLESS: ProfileName = VbcLosslessProfile; break; } IWMEncProfileCollection ProColl = m_Encoder.ProfileCollection; IWMEncProfile Pro; for (int i = 0; i < ProColl.Count; i++) { Pro = ProColl.Item(i); if (Pro.Name == ProfileName) { SrcGrp.set_Profile(Pro); return(true); } } return(false); }
public void SetProfile() { m_profileCollection = m_encoder.ProfileCollection; for (int i = 0; i < m_profileCollection.Count; i++) { m_profile = m_profileCollection.Item(i); if (m_profile.Name == Flag_configpro) { m_srcGrp.set_Profile(m_profile); break; } } }
static void Main() { try { // Create a WMEncoder object. WMEncoder Encoder = new WMEncoder(); // Retrieve the source group collection. IWMEncSourceGroupCollection SrcGrpColl = Encoder.SourceGroupCollection; // Add a source group to the collection. IWMEncSourceGroup SrcGrp = SrcGrpColl.Add("SG_1"); // Add a video and audio source to the source group. IWMEncSource SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO); SrcAud.SetInput("C:\\Inputfile.mpg", "", ""); IWMEncVideoSource2 SrcVid = (IWMEncVideoSource2)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); SrcVid.SetInput("C:\\Inputfile.mpg", "", ""); // Crop 2 pixels from each edge of the video image. SrcVid.CroppingBottomMargin = 2; SrcVid.CroppingTopMargin = 2; SrcVid.CroppingLeftMargin = 2; SrcVid.CroppingRightMargin = 2; // Specify a file object in which to save encoded content. IWMEncFile File = Encoder.File; File.LocalFileName = "C:\\OutputFile.wmv"; // Choose a profile from the collection. IWMEncProfileCollection ProColl = Encoder.ProfileCollection; IWMEncProfile Pro; for (int i = 0; i < ProColl.Count; i++) { Pro = ProColl.Item(i); if (Pro.Name == "Windows Media Video 8 for Local Area Network (384 Kbps)") { SrcGrp.set_Profile(Pro); break; } } // Fill in the description object members. IWMEncDisplayInfo Descr = Encoder.DisplayInfo; Descr.Author = "Author name"; Descr.Copyright = "Copyright information"; Descr.Description = "Text description of encoded content"; Descr.Rating = "Rating information"; Descr.Title = "Title of encoded content"; // Add an attribute to the collection. IWMEncAttributes Attr = Encoder.Attributes; Attr.Add("URL", "IP address"); // Start the encoding process. // Wait until the encoding process stops before exiting the application. Encoder.PrepareToEncode(true); Encoder.Start(); Console.WriteLine("Press Enter when the file has been encoded."); Console.ReadLine(); // Press Enter after the file has been encoded. } catch (Exception e) { // TODO: Handle exceptions. } }
public void SetProfile() { m_profileCollection = m_encoder.ProfileCollection; for(int i = 0; i < m_profileCollection.Count; i++) { m_profile = m_profileCollection.Item(i); if( m_profile.Name == Flag_configpro) { m_srcGrp.set_Profile(m_profile); break; } } }
//To Start the Recording. private void startRecordingToolStripMenuItem_Click(object sender, EventArgs e) { IWMEncProfile SelProfile; IWMEncSource AudioSrc; try { if (DesktopEncoder != null) { if (DesktopEncoder.RunState == WMENC_ENCODER_STATE.WMENC_ENCODER_PAUSED) { DesktopEncoder.Start(); return; } } DesktopEncoderAppln = new WMEncoderApp(); DesktopEncoder = DesktopEncoderAppln.Encoder; IWMEncSourceGroupCollection SrcGroupCollection = DesktopEncoder.SourceGroupCollection; IWMEncSourceGroup SrcGroup = SrcGroupCollection.Add("SG_1"); IWMEncVideoSource2 VideoSrc = (IWMEncVideoSource2)SrcGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); //Set Audio Source. if (addAudio.Checked) { AudioSrc = SrcGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO); if (txtAudioFile.Text.Trim() != "") { if (File.Exists(txtAudioFile.Text.Trim())) { AudioSrc.SetInput(txtAudioFile.Text.Trim(), "", ""); } else { AudioSrc.SetInput("Default_Audio_Device", "Device", ""); } } else { AudioSrc.SetInput("Default_Audio_Device", "Device", ""); } } //Set Video Source:Desktop. VideoSrc.SetInput("ScreenCapture1", "ScreenCap", ""); IWMEncProfileCollection ProfileCollection = DesktopEncoder.ProfileCollection; ProfileCollection = DesktopEncoder.ProfileCollection; int lLength = ProfileCollection.Count; //Set Profile. if (toolstripEnableBroadcast.Checked && txtPortNbr.Text.Trim() != "") { IWMEncBroadcast broadcast = DesktopEncoder.Broadcast; broadcast.set_PortNumber(WMENC_BROADCAST_PROTOCOL.WMENC_PROTOCOL_HTTP, Convert.ToInt32(txtPortNbr.Text.Trim())); for (int i = 0; i <= lLength - 1; i++) { SelProfile = ProfileCollection.Item(i); if (SelProfile.Name == "Windows Media Video 8 for Local Area Network (768 Kbps)") { SrcGroup.set_Profile((IWMEncProfile)SelProfile); break; } } } else { for (int i = 0; i <= lLength - 1; i++) { SelProfile = ProfileCollection.Item(i); if (SelProfile.Name == "Screen Video/Audio High (CBR)") { SrcGroup.set_Profile((IWMEncProfile)SelProfile); break; } } } //Local File to Store Recording temporarily. IWMEncFile inputFile = DesktopEncoder.File; inputFile.LocalFileName = "C:\\TempRecording.wmv"; DesktopEncoder.PrepareToEncode(true); DesktopEncoder.Start(); tmrRcCounter.Enabled = true; recordStarttime = DateTime.Now; if (toolstripEnableBroadcast.Checked && txtPortNbr.Text.Trim() != "") { //Start Timer to Count Viewers connected to Broadcast. tmrViewerCount.Enabled = true; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void InitializeEncoder() { SrcGrpColl = Encoder.SourceGroupCollection; SrcGrp = SrcGrpColl.Add("SG_1"); SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO); SrcVid = (IWMEncVideoSource2)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); SrcAud.SetInput("Default_Audio_Device", "Device", ""); SrcVid.SetInput("Default_Video_Device", "Device", ""); ProColl = Encoder.ProfileCollection; for (int i = 0; i < ProColl.Count; i++) { Pro = ProColl.Item(i); data.Add(Pro.Name); if (Pro.Name == Codec) { SrcGrp.set_Profile(Pro); break; } } BrdCst = Encoder.Broadcast; BrdCst.set_PortNumber(WMENC_BROADCAST_PROTOCOL.WMENC_PROTOCOL_HTTP, Port); }
/// <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(); }
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); }