protected virtual void DoEncodeProgress(EncodeProgressEventArgs e) { if (OnEncodeProgress != null) { OnEncodeProgress(this, e); } }
protected virtual void DoEncodeProgress(EncodeProgressEventArgs e) { if (this.OnEncodeProgress != null) { this.OnEncodeProgress(this, e); } }
void proc_ErrorDataReceived(object sender, DataReceivedEventArgs e) { if (e.Data != null) { tempEncodedVideo.EncodingLog += e.Data + Environment.NewLine; if (e.Data.StartsWith("frame")) { iProgressErrorCount = 0; EncodeProgressEventArgs epe = new EncodeProgressEventArgs(); epe.RawOutputLine = e.Data; epe.TotalFrames = tempVideoFile.TotalFrames; string[] parts = e.Data.Split(new string[] { " ", "=" }, StringSplitOptions.RemoveEmptyEntries); long lCurrentFrame = 0L; Int64.TryParse(parts[1], out lCurrentFrame); epe.CurrentFrame = lCurrentFrame; short sFPS = 0; Int16.TryParse(parts[3], out sFPS); epe.FPS = sFPS; double dCurrentFrame = (double)epe.CurrentFrame; double dTotalFrames = (double)epe.TotalFrames; short sPercentage = (short)Math.Round(dCurrentFrame * 100 / dTotalFrames, 0); epe.Percentage = sPercentage; if (tempCaller != null) { tempCaller.BeginInvoke(new EncodeProgressEventHandler(OnEncodeProgress), tempCaller, epe); } else { DoEncodeProgress(epe); } } else { iProgressErrorCount++; } } else { iProgressErrorCount++; } if (iProgressErrorCount > PROGRESS_ERROR_LIMIT) { Process proc = (Process)sender; try { proc.Kill(); } catch { } } }
private void EncoderOnEncodeProgress(object sender, EncodeProgressEventArgs e) { // Encode progress should be from 50 to 100 percent progress = 50 + (int)((float)e.Percentage / 2f); speed = e.BytesPerSecond; eta = e.Eta; SetChanged(); }
private void proc_ErrorDataReceived(object sender, DataReceivedEventArgs e) { if (e.Data != null) { this.tempEncodedVideo.EncodingLog = this.tempEncodedVideo.EncodingLog + e.Data + Environment.NewLine; if (e.Data.StartsWith("frame")) { this.iProgressErrorCount = 0; EncodeProgressEventArgs args = new EncodeProgressEventArgs { RawOutputLine = e.Data, TotalFrames = this.tempVideoFile.TotalFrames }; string[] strArray = e.Data.Split(new string[] { " ", "=" }, StringSplitOptions.RemoveEmptyEntries); long result = 0L; long.TryParse(strArray[1], out result); args.CurrentFrame = result; short num2 = 0; short.TryParse(strArray[3], out num2); args.FPS = num2; double currentFrame = args.CurrentFrame; double totalFrames = args.TotalFrames; short num5 = (short) Math.Round((double) ((currentFrame * 100.0) / totalFrames), 0); args.Percentage = num5; if (this.tempCaller != null) { this.tempCaller.BeginInvoke(new EncodeProgressEventHandler(this.OnEncodeProgress.Invoke), new object[] { this.tempCaller, args }); } else { this.DoEncodeProgress(args); } } else { this.iProgressErrorCount++; } } else { this.iProgressErrorCount++; } if (this.iProgressErrorCount > 100) { Process process = (Process) sender; try { process.Kill(); } catch { } } }
/// <summary> /// Handles process progress /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void proc_ErrorDataReceived(object sender, DataReceivedEventArgs e) { if (e.Data != null) { tempEncodedVideo.EncodingLog += e.Data + Environment.NewLine; if (e.Data.StartsWith("frame")) { //Reset progress error count iProgressErrorCount = 0; //Create a new progress event object EncodeProgressEventArgs epe = new EncodeProgressEventArgs(); //Set raw data line epe.RawOutputLine = e.Data; //Set total frames epe.TotalFrames = tempVideoFile.TotalFrames; //Split the raw string string[] parts = e.Data.Split(new string[] { " ", "=" }, StringSplitOptions.RemoveEmptyEntries); //Parse current frame long lCurrentFrame = 0L; Int64.TryParse(parts[1], out lCurrentFrame); epe.CurrentFrame = lCurrentFrame; //Parse FPS short sFPS = 0; Int16.TryParse(parts[3], out sFPS); epe.FPS = sFPS; //Calculate percentage double dCurrentFrame = (double)epe.CurrentFrame; double dTotalFrames = (double)epe.TotalFrames; short sPercentage = (short)Math.Round(dCurrentFrame * 100 / dTotalFrames, 0); epe.Percentage = sPercentage; //Invoke/Fire Real progress event if (tempCaller != null) tempCaller.BeginInvoke(new EncodeProgressEventHandler(OnEncodeProgress), tempCaller, epe); else DoEncodeProgress(epe); } else //Increment progress error iProgressErrorCount++; } else //Increment progress error iProgressErrorCount++; //If ProgressErrorCount is more than limit, then kill the process if (iProgressErrorCount > PROGRESS_ERROR_LIMIT) { //Get the process Process proc = (Process)sender; //Murder try { proc.Kill(); } catch { } } }
/// <summary> /// Handles process progress /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void proc_ErrorDataReceived(object sender, DataReceivedEventArgs e) { if (e.Data != null) { tempEncodedVideo.EncodingLog += e.Data + Environment.NewLine; if (e.Data.StartsWith("frame")) { //Reset progress error count iProgressErrorCount = 0; //Create a new progress event object EncodeProgressEventArgs epe = new EncodeProgressEventArgs(); //Set raw data line epe.RawOutputLine = e.Data; //Set total frames epe.TotalFrames = tempVideoFile.TotalFrames; //Split the raw string string[] parts = e.Data.Split(new string[] { " ", "=" }, StringSplitOptions.RemoveEmptyEntries); //Parse current frame long lCurrentFrame = 0L; Int64.TryParse(parts[1], out lCurrentFrame); epe.CurrentFrame = lCurrentFrame; //Parse FPS short sFPS = 0; Int16.TryParse(parts[3], out sFPS); epe.FPS = sFPS; //Calculate percentage double dCurrentFrame = (double)epe.CurrentFrame; double dTotalFrames = (double)epe.TotalFrames; short sPercentage = (short)Math.Round(dCurrentFrame * 100 / dTotalFrames, 0); epe.Percentage = sPercentage; //Invoke/Fire Real progress event if (tempCaller != null) { tempCaller.BeginInvoke(new EncodeProgressEventHandler(OnEncodeProgress), tempCaller, epe); } else { DoEncodeProgress(epe); } } else { //Increment progress error iProgressErrorCount++; } } else { //Increment progress error iProgressErrorCount++; } //If ProgressErrorCount is more than limit, then kill the process if (iProgressErrorCount > PROGRESS_ERROR_LIMIT) { //Get the process Process proc = (Process)sender; //Murder try { proc.Kill(); } catch { } } }
/// <summary> /// Handles process progress /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void proc_ErrorDataReceived(object sender, DataReceivedEventArgs e) { if (e.Data != null) { tempEncodedVideo.EncodingLog += e.Data + Environment.NewLine; if (e.Data.StartsWith("frame")) { //Reset progress error count iProgressErrorCount = 0; //Create a new progress event object EncodeProgressEventArgs epe = new EncodeProgressEventArgs(); //Set raw data line epe.RawOutputLine = e.Data; //Set total frames epe.TotalFrames = tempVideoFile.TotalFrames; //Split the raw string string[] parts = e.Data.Split(new string[] { " ", "=" }, StringSplitOptions.RemoveEmptyEntries); //Parse current frame long lCurrentFrame = 0L; Int64.TryParse(parts[1], out lCurrentFrame); epe.CurrentFrame = lCurrentFrame; //Parse FPS short sFPS = 0; Int16.TryParse(parts[3], out sFPS); epe.FPS = sFPS; //Calculate percentage double dCurrentFrame = (double)epe.CurrentFrame; double dTotalFrames = (double)epe.TotalFrames; short sPercentage = (short)Math.Round(dCurrentFrame * 100 / dTotalFrames, 0); epe.Percentage = sPercentage; //Invoke/Fire Real progress event if (tempCaller != null) tempCaller.BeginInvoke(new EncodeProgressEventHandler(OnEncodeProgress), tempCaller, epe); else DoEncodeProgress(epe); } else if (e.Data.Contains("time=")) { var time = TimeSpan.Parse(e.Data.Substring(e.Data.IndexOf("time=") + 5, 8)); var seconds = time.TotalSeconds; var totalSeconds = tempVideoFile.Duration.TotalSeconds; var epe = new EncodeProgressEventArgs(); epe.Percentage = (short)Math.Round(seconds / totalSeconds * 100.0); var sizeString = e.Data.Substring(e.Data.IndexOf("size=") + 5); var sizeEnd = sizeString.IndexOf("kB"); sizeString = sizeString.Substring(0, sizeEnd).Trim(); var size = int.Parse(sizeString) * 1024; if (lastSizeTime != null) { var elapsed = (DateTime.Now - lastSizeTime).TotalMilliseconds; var processed = size - lastSize; epe.BytesPerSecond = (int)Math.Round(processed * (1000 / elapsed)); // Eta var timeProcessed = (int)Math.Round(seconds - lastTime); var timePerSecond = (int)Math.Round(timeProcessed * (1000 / elapsed)); var timeLeft = tempVideoFile.Duration.TotalSeconds - seconds; epe.Eta = (long)Math.Round((float)timeLeft / (float)timePerSecond); } lastSizeTime = DateTime.Now; lastSize = size; lastTime = (long)seconds; if (epe.BytesPerSecond < 0) epe.BytesPerSecond = 0; if (epe.Eta < 0) epe.Eta = 0; if (tempCaller != null) tempCaller.BeginInvoke(new EncodeProgressEventHandler(OnEncodeProgress), tempCaller, epe); else DoEncodeProgress(epe); } else //Increment progress error iProgressErrorCount++; } else //Increment progress error iProgressErrorCount++; //If ProgressErrorCount is more than limit, then kill the process if (iProgressErrorCount > PROGRESS_ERROR_LIMIT) { //Get the process Process proc = (Process)sender; //Murder try { proc.Kill(); } catch { } } }