private void EncodeFile(EncodingProfileEnum Profile, EncoderInfo Info) { try { m_CurrentInfo = Info; DateTime Now = DateTime.Now; lblStatus.Text = " Starting to encode " + m_CurrentProfile.ToString() + " Starting time = " + Now.ToLongTimeString(); m_EncodingDone = false; // Create a WMEncoder object. m_Encoder = new WMEncoder(); m_Encoder.OnStateChange += new _IWMEncoderEvents_OnStateChangeEventHandler( OnStateChange); // Retrieve the source group collection. IWMEncSourceGroupCollection SrcGrpColl = m_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(Info.FileNameAndPath, "", ""); // Specify a file object in which to save encoded content. SetOutputFileName(Info.FileNameNoExtension); SelectProfile(SrcGrp); // Fill in the description object members. IWMEncDisplayInfo Descr = m_Encoder.DisplayInfo; Descr.Author = Info.Author; Descr.Copyright = "Valley Bible Church @2005"; Descr.Description = Info.Description; Descr.Rating = "All Audiences"; Descr.Title = Info.MessageTitle; // Add an attribute to the collection. IWMEncAttributes Attr = m_Encoder.Attributes; Attr.Add("URL", "IP address"); // Start the encoding process. // Wait until the encoding process stops before exiting the application. m_Encoder.PrepareToEncode(true); m_Encoder.Start(); } catch (Exception e) { lblError.Text = e.ToString(); Debug.WriteLine(e.ToString()); m_CurrentInfo = null; } }
public void InitializeEncoder() { try { frm_Rec = new WebMeeting.Client.Screen_Capture.frm_Rec(); config = new Config(); config.cfgFile = "WebMeeting.exe.config"; // create encoder object m_encoder = new WMEncoder(); m_encoder.DisplayInfo.Author = "Zaeem"; m_encoder.DisplayInfo.Copyright = "Uraan Software Solutions"; m_encoder.DisplayInfo.Description = "Uraan Generated Media File for Screen Recording"; m_encoder.DisplayInfo.Title = "Recorded Screen"; m_encoder.DisplayInfo.Title = "Recorded Screen"; m_encoder.DisplayInfo.Rating = "1"; m_encoder.DisplayInfo.Description = "This file is Generated through CampusNav developed by Uraan Software Solution"; // retrive source group collection m_sourceGroupCollection = m_encoder.SourceGroupCollection; // add a source group to collection m_srcGrp = m_sourceGroupCollection.Add("SG_1"); m_sourceEnumDlg = new SourceEnum(); // add a screen source if (EnumerateAudioSources()) { m_audSource = m_srcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO); m_audSource.SetInput(m_szAudioSource, "Device", ""); } // set screen as source m_screenSource = (IWMEncVideoSource2)m_srcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); m_screenSource.SetInput("ScreenCapture1", "ScreenCap", ""); } catch (Exception exp) { WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Video Recordong Module ===>Screen Capture.cs line==> 99", exp, "Error Loading Encoder: " + exp.Message.ToString(), false); if (MessageBox.Show("Either You do not have required components of Windows Media Encoder or they are corrupted on your Machine: " + /*+exp.Message.ToString() + */ ". Do you want to download now?", "WebMeeting", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { Win32.Shell32.ShellExecute(0, "Open", WebMeeting.Client.Info.getInstance().WebsiteName + "/wmencoder.exe", "", "", 1); } //WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Error Stoping encoder: " + exp.Message.ToString()); //Trace.WriteLine(exp.ToString()+"---"+exp.Message+"---"+exp.Source+exp.StackTrace+"---"+exp.TargetSite+"---"+exp.InnerException); } }
/** * Set source. * @param type : source type. * @param name : source name. */ public DVRBResult SetSource(ESourceType type, string name) { try { string scheme = string.Empty; IWMEncSource source = null; switch (type) { case ESourceType.DeviceAudio: scheme = "Device"; if (this.audioSource == null) { this.audioSource = (IWMEncAudioSource)this.sourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO); } source = this.audioSource; break; case ESourceType.DeviceVideo: scheme = "Device"; if (this.videoSource == null) { this.videoSource = (IWMEncVideoSource)this.sourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); } source = this.videoSource; break; case ESourceType.DesktopVideo: scheme = "ScreenCap"; if (this.videoSource == null) { this.videoSource = (IWMEncVideoSource)this.sourceGroup.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); } source = this.videoSource; break; } log.Debug("Setting " + scheme + " -->" + name); source.SetInput(name, scheme, string.Empty); } catch (Exception e) { return(new DVRBResult(DVRBResult.ERROR, e.Message)); } return(new DVRBResult()); }
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 InitializeEncoder() { try { frm_Rec=new WebMeeting.Client.Screen_Capture.frm_Rec(); config=new Config(); config.cfgFile = "WebMeeting.exe.config"; // create encoder object m_encoder = new WMEncoder(); m_encoder.DisplayInfo.Author="Zaeem"; m_encoder.DisplayInfo.Copyright="Uraan Software Solutions"; m_encoder.DisplayInfo.Description="Uraan Generated Media File for Screen Recording"; m_encoder.DisplayInfo.Title="Recorded Screen"; m_encoder.DisplayInfo.Title="Recorded Screen"; m_encoder.DisplayInfo.Rating="1"; m_encoder.DisplayInfo.Description="This file is Generated through CampusNav developed by Uraan Software Solution"; // retrive source group collection m_sourceGroupCollection = m_encoder.SourceGroupCollection; // add a source group to collection m_srcGrp = m_sourceGroupCollection.Add("SG_1"); m_sourceEnumDlg= new SourceEnum(); // add a screen source if(EnumerateAudioSources()) { m_audSource = m_srcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO); m_audSource.SetInput(m_szAudioSource, "Device", ""); } // set screen as source m_screenSource = (IWMEncVideoSource2)m_srcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); m_screenSource.SetInput("ScreenCapture1", "ScreenCap", ""); } catch(Exception exp) { WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Video Recordong Module ===>Screen Capture.cs line==> 99",exp,"Error Loading Encoder: " + exp.Message.ToString(),false); if( MessageBox.Show("Either You do not have required components of Windows Media Encoder or they are corrupted on your Machine: "+ /*+exp.Message.ToString() + */". Do you want to download now?","WebMeeting",MessageBoxButtons.YesNo,MessageBoxIcon.Information) == DialogResult.Yes) { Win32.Shell32.ShellExecute(0,"Open",WebMeeting.Client.Info.getInstance().WebsiteName + "/wmencoder.exe","","",1); } //WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Error Stoping encoder: " + exp.Message.ToString()); //Trace.WriteLine(exp.ToString()+"---"+exp.Message+"---"+exp.Source+exp.StackTrace+"---"+exp.TargetSite+"---"+exp.InnerException); } }
private void button1_Click(object sender, EventArgs e) { try { Encoder = new WMEncoder(); IWMEncSourceGroup SrcGrp; IWMEncSourceGroupCollection SrcGrpColl; SrcGrpColl = Encoder.SourceGroupCollection; SrcGrp = SrcGrpColl.Add("SG_1"); IWMEncSource SrcVid = null; IWMEncSource SrcAud = null; SrcVid = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO); SrcAud.SetInput("Default_Audio_Device", "Device", ""); SrcVid.SetInput("ScreenCapture1", "ScreenCap", ""); IWMEncProfileCollection ProColl; IWMEncProfile Pro; int i; long lLength; ProColl = Encoder.ProfileCollection; lLength = ProColl.Count; for (i = 0; i < lLength - 1; i++) { Pro = ProColl.Item(i); Console.WriteLine("<><>>" + Pro.Name); if (Pro.Name == "屏幕视频/音频 - 高(CBR)") { SrcGrp.set_Profile(Pro); break; } } IWMEncDisplayInfo Descr; Descr = Encoder.DisplayInfo; Descr.Author = ""; Descr.Copyright = ""; Descr.Description = ""; Descr.Rating = ""; Descr.Title = ""; IWMEncAttributes Attr; Attr = Encoder.Attributes; IWMEncFile File; File = Encoder.File; //if (label1.Text != string.Empty) //{ // File.LocalFileName = @"C:\1.WMA"; //保存路径 //} //else //{ // MessageBox.Show("请先选择路径!"); // return; //} File.LocalFileName = @"C:\1.WMA"; //保存路径 Encoder.Start(); } catch (Exception ex) { Encoder.Stop(); } }
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="profileName"></param> private static void CombineParts(string dir) { WMEncoderApp app = new WMEncoderAppClass(); IWMEncoder2 enc = app.Encoder as IWMEncoder2; IWMEncSourceGroupCollection sgcol = enc.SourceGroupCollection; WMEncProfile2 pf = new WMEncProfile2Class(); pf.LoadFromFile(dir + "/default.prx"); int index = 0; IWMEncSourceGroup2 sg2 = null; foreach (FileInfo fi in new DirectoryInfo(dir).GetFiles("dest*.wmv")) { Console.WriteLine("target : {0}", fi.Name); sg2 = sgcol.Add("sg" + index) as IWMEncSourceGroup2; sg2.set_Profile(pf); IWMEncSource asrc = sg2.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO); asrc.SetInput(fi.FullName, "", ""); IWMEncSource vsrc = sg2.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); vsrc.SetInput(fi.FullName, "", ""); //sg2.AutoSetFileSource(fi.FullName); if (index > 0) { sg2.SetAutoRollover(-1, "sg" + (index - 1)); } index++; } sgcol.Active = sg2; FileInfo destFile = new FileInfo("default_all.wmv"); destFile.Delete(); enc.File.LocalFileName = destFile.FullName; enc.PrepareToEncode(true); enc.Start(); Console.WriteLine("combine start"); while (enc.RunState != WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED) { Thread.Sleep(2000); } Console.WriteLine("combine end : 0x{0}", enc.ErrorState.ToString("X")); Marshal.ReleaseComObject(pf); Marshal.ReleaseComObject(sgcol); Marshal.ReleaseComObject(enc); Marshal.ReleaseComObject(app); }