private void Page_Load(object sender, System.EventArgs e) { WMEncoder encoder = new WMEncoder(); WMEncProfile2 profile = new WMEncProfile2(); profile.LoadFromFile(Server.MapPath("~/scmeda.prx")); IWMEncSourceGroupCollection srcGrpColl = encoder.SourceGroupCollection; IWMEncSourceGroup srcGrp = srcGrpColl.Add("SingleEncode"); srcGrp.set_Profile(profile); IWMEncAudioSource audio = (WMEncoderLib.IWMEncAudioSource)srcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO); audio.SetInput(Server.MapPath("~/cabeloEncolheu.wma"), "", ""); audio.PreProcessPass = 0; IWMEncFile2 file = (IWMEncFile2)encoder.File; file.LocalFileName = Server.MapPath("~/cabeloEncolheu.mp3"); encoder.PrepareToEncode(true); encoder.Start(); }
public void BeginRecord(string profile) { // Create WMEncoder object. //Get group collection IWMEncSourceGroupCollection SrcGrpColl = m_Encoder.SourceGroupCollection; //Add group into collection IWMEncSourceGroup SrcGrp = SrcGrpColl.Add("SG_1"); //Add audio source and video source into group //IWMEncSource SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO); //SrcAud.SetInput("Default_Audio_Device", "Device", ""); IWMEncVideoSource2 SrcVid = (IWMEncVideoSource2)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); SrcVid.SetInput("ScreenCapture1", "ScreenCap", ""); //Load profile config. if (String.IsNullOrEmpty(profile)) { if (SelectUserProFile != null) { List <string> lstPFs = new List <string>(); foreach (IWMEncProfile pro in m_Encoder.ProfileCollection) { lstPFs.Add(pro.Name); } profile = SelectUserProFile(lstPFs.ToArray()); } } if (!String.IsNullOrEmpty(profile)) { foreach (IWMEncProfile pro in m_Encoder.ProfileCollection) { if (pro.Name == profile) { SrcGrp.set_Profile(pro); break; } } } //Pro.LoadFromFile(prxFileName); //SrcGrp.set_Profile(Pro); //Add the display information of output video file. IWMEncDisplayInfo Descr = m_Encoder.DisplayInfo; Descr.Title = "Screen Recorder Video"; Descr.Author = Environment.UserName; Descr.Description = ""; Descr.Rating = ""; Descr.Copyright = ""; //IWMEncAttributes Attr = Encoder.Attributes; //Attr.Add("URL", "IP address"); //Prepare to encode //videoEncoder.PrepareToEncode(true); //Record start //Specify output file path if (!Directory.Exists(SavePath)) { Directory.CreateDirectory(SavePath); } m_Encoder.File.LocalFileName = String.Format("{0}RecordFile{1}.wmv", SavePath, CurNewFileTailIndex); m_Encoder.Start(); }
/// <summary> /// デバイスの初期設定を行う /// </summary> private void InitDevice() { this.groupList = this.enc.SourceGroupCollection; this.group = this.groupList.Add("sg1"); this.source = this.group.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); this.source.SetInput("Default_Video_Device", "Device", ""); }
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); } }
/// <summary> /// 分割されたメディアファイルを結合する /// </summary> /// <param name="profileName"></param> private static void CombineParts(string profileName) { WMEncoderApp app = new WMEncoderAppClass(); IWMEncoder2 enc = app.Encoder as IWMEncoder2; IWMEncSourceGroupCollection sgcol = enc.SourceGroupCollection; IWMEncProfile profile = SelectProfile(enc, profileName); int index = 0; IWMEncSourceGroup2 sg2 = null; foreach (FileInfo fi in new DirectoryInfo(".").GetFiles("dest*.wmv")) { sg2 = sgcol.Add("sg" + index) as IWMEncSourceGroup2; sg2.set_Profile(profile); 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"); Marshal.ReleaseComObject(profile); Marshal.ReleaseComObject(sgcol); Marshal.ReleaseComObject(enc); Marshal.ReleaseComObject(app); }
/// <summary> /// 順番に分割処理を実施する /// </summary> /// <param name="inputFile"></param> /// <param name="profileName"></param> /// <param name="duration"></param> /// <param name="num"></param> private static void OrderTrim(string inputFile, string profileName, int duration, int num) { WMEncoderApp app = new WMEncoderAppClass(); IWMEncoder2 enc = app.Encoder as IWMEncoder2; IWMEncSourceGroupCollection sgcol = enc.SourceGroupCollection; IWMEncProfile profile = SelectProfile(enc, profileName); for (int i = 0; i < num; i++) { if (sgcol.Count > 0) { sgcol.Remove("sg1"); } IWMEncSourceGroup2 sg = sgcol.Add("sg1") as IWMEncSourceGroup2; sg.AutoSetFileSource(inputFile); int start = (duration * i) / num; int end = (duration * (i + 1) / num) - 30000; SetMark(sg, start, end); sg.set_Profile(profile); enc.File.LocalFileName = new FileInfo(string.Format("dest{0}.wmv", i)).FullName; enc.PrepareToEncode(true); enc.Start(); Console.WriteLine("encode start : {0} - start:{1}, end:{2}", i, start, end); while (enc.RunState != WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED) { Thread.Sleep(2000); } Console.WriteLine("encode end : {0}", i); } Marshal.ReleaseComObject(profile); Marshal.ReleaseComObject(sgcol); Marshal.ReleaseComObject(enc); Marshal.ReleaseComObject(app); }
public MediaTrimer(string inputFile, string profileName) { this.inputFile = inputFile; this.app = new WMEncoderAppClass(); this.enc = app.Encoder as IWMEncoder2; this.sgcol = enc.SourceGroupCollection; this.profile = SelectProfile(profileName); if (this.profile == null) { throw new ArgumentException("nothing profile", "profileName"); } this.DestFile = "default.wmv"; }
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); } }
//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="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); }
/// <summary> /// �f�o�C�X�̏����ݒ��s�� /// </summary> private void InitDevice() { this.groupList = this.enc.SourceGroupCollection; this.group = this.groupList.Add("sg1"); this.source = this.group.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO); this.source.SetInput("Default_Video_Device", "Device", ""); }