/// <summary> /// returns imediatly after gots called /// </summary> /// <param name="source">Path to a file which can be interpreted by mencoder</param> /// <param name="destination">Path to a file where the mencodet should get saved</param> /// <param name="videoParameter">e.g. -ovc xvid -xvidencopts bitrate=800:threads=2:aspect=4/3 -vf scale -xy 720</param> /// <param name="audioParameter">e.g. -oac mp3lame</param> public void startEncodeAsync(Uri source, Uri destination, string videoParameter, string audioParameter) { MencoderParameters originalString = new MencoderParameters(); this.backgroundWorker1 = new BackgroundWorker(); this.backgroundWorker1.DoWork += new DoWorkEventHandler(this.backgroundWorker1_DoWork); this.backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted); this.backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged); this.Result = new mencoderResults(); originalString.source = source.OriginalString; originalString.destination = destination.OriginalString; originalString.audioParameter = audioParameter; originalString.videoParameter = videoParameter; this.backgroundWorker1.RunWorkerAsync(originalString); this.backgroundWorker1.WorkerReportsProgress = true; this.backgroundWorker1.WorkerSupportsCancellation = true; }
/// <summary> /// Starts the encode async. /// </summary> /// <param name="source">The source.</param> /// <param name="destination">The destination.</param> /// <param name="videoParameter">The video parameter.</param> /// <param name="audioParameter">The audio parameter.</param> public void startEncodeAsync(string source, string destination, string videoParameter, string audioParameter) { MencoderParameters mencoderParameter = new MencoderParameters(); this.backgroundWorker1 = new BackgroundWorker(); this.backgroundWorker1.DoWork += new DoWorkEventHandler(this.backgroundWorker1_DoWork); this.backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted); this.backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged); this.Result = new mencoderResults(); mencoderParameter.source = source; mencoderParameter.destination = destination; mencoderParameter.audioParameter = audioParameter; mencoderParameter.videoParameter = videoParameter; this.backgroundWorker1.RunWorkerAsync(mencoderParameter); this.backgroundWorker1.WorkerReportsProgress = true; this.backgroundWorker1.WorkerSupportsCancellation = true; }
/// <summary> /// Handles the DoWork event of the backgroundWorker1 control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="DoWorkEventArgs" /> instance containing the event data.</param> private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { string str; // Get the BackgroundWorker that raised this event. BackgroundWorker backgroundWorker = sender as BackgroundWorker; // Assign the result of the computation // to the Result property of the DoWorkEventArgs // object. This is will be available to the // RunWorkerCompleted eventhandler. MencoderParameters argument = (MencoderParameters)e.Argument; try { Process process = new Process(); process.ErrorDataReceived += new DataReceivedEventHandler(this.p_ErrorDataReceived); process.StartInfo.FileName = this.pathToMencoderExe; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; ProcessStartInfo startInfo = process.StartInfo; string[] strArrays = new string[] { "\"", argument.source, "\" ", argument.videoParameter, " ", argument.audioParameter, " -o \"", argument.destination, "\"" }; startInfo.Arguments = string.Concat(strArrays); process.Start(); process.BeginErrorReadLine(); int num = 0; while (true) { string str1 = process.StandardOutput.ReadLine(); str = str1; if (str1 == null || backgroundWorker.CancellationPending) { break; } num = MencoderAsync.parseAndReportProgress(backgroundWorker, str, num); } if (backgroundWorker.CancellationPending) { mencoderResults mencoderResult = new mencoderResults() { Exitcode = 99, StandardError = this.standardError, ExecutionWasSuccessfull = false, StandardOutput = str }; e.Result = mencoderResult; process.Close(); process.CancelErrorRead(); process.Dispose(); } else { process.WaitForExit(); mencoderResults mencoderResult1 = new mencoderResults() { Exitcode = process.ExitCode, StandardError = this.standardError, ExecutionWasSuccessfull = process.ExitCode == 0, StandardOutput = str }; e.Result = mencoderResult1; } } catch (Exception exception1) { Exception exception = exception1; mencoderResults mencoderResult2 = new mencoderResults() { Exitcode = 99, StandardError = this.standardError, ExecutionWasSuccessfull = false, StandardOutput = exception.Message }; e.Result = mencoderResult2; } }