/// <summary> /// Create an array of frame images from a video file /// </summary> /// <param name="Video">Video file</param> /// <param name="ImagePath">Path to hold frame band images</param> /// <param name="FFmpeg">ffmpeg executable path</param> /// <param name="Height">Height of generated frame bands.</param> private static void CreateImages(string Video, string ImagePath, string FFmpeg, int Height) { VideoInfo VI = Tools.GetVideoInfo(Video); if (Height < 1) { Height = VI.Resolution.Height; } DateTime Start = DateTime.Now; Console.Error.WriteLine("Press [q] to abort processing and use existing frames"); using (Process P = Tools.BeginConversion(Video, ImagePath, Height)) { using (StreamReader SR = P.StandardError) { StatusLine SL; int Y = Console.CursorTop; while (!SR.EndOfStream) { if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Q) { P.StandardInput.WriteLine("q"); } SL = new StatusLine(SR.ReadLine()); TimeSpan Estimate = new TimeSpan(0, 0, (int)(VI.Duration.TotalSeconds / SL.Speed)); TimeSpan CurrentTime = Tools.CutToSeconds(DateTime.Now.Subtract(Start)); if (SL.Frame > 0) { Console.SetCursorPosition(0, Y); Console.Error.WriteLine(@"Time : {0} Speed : {1,-6} Frames : {2,-6} Estimate: {3} Current : {4}", SL.Time, SL.Speed, SL.Frame, Estimate, CurrentTime); } } } //Instead of just waiting, spawn the Process hidden and show the progress of stderr. //I have some code for this already, but was too lazy to go and copy it. P.WaitForExit(); } }
public frmEncoder(string TempDir, string SourceFile, string DestinationFile, int BandHeight, bool SingleColor) { this.TempDir = TempDir; this.SourceFile = SourceFile; this.DestinationFile = DestinationFile; this.BandHeight = BandHeight; this.SingleColor = SingleColor; Tools.ThreadExit += Tools_ThreadExit; VI = Tools.GetVideoInfo(SourceFile); InitializeComponent(); pbStatus.Maximum = (int)VI.Duration.TotalSeconds; Encoder = new Thread(delegate() { var Start = DateTime.Now; using (Process P = Tools.BeginConversion(SourceFile, TempDir, BandHeight)) { using (StreamReader SR = P.StandardError) { StatusLine SL; while (!SR.EndOfStream) { if (Aborted) { P.StandardInput.WriteLine("q"); } SL = new StatusLine(SR.ReadLine()); if (!Aborted) { TimeSpan Estimate = new TimeSpan(0, 0, (int)(VI.Duration.TotalSeconds / SL.Speed)); if (SL.Frame > 0) { this.Invoke((MethodInvoker) delegate { lblEncodingProgress.Text = string.Format(@"Status: Speed : {0}x playback Video time : {1} / {5} Current frame : {2} Progress : {3}% Estimated encoding time: {4} Encoding time : {6}", SL.Speed, SL.Time, SL.Frame, Perc(SL.Frame, (int)VI.Duration.TotalSeconds), Estimate, VI.Duration, Tools.CutToSeconds(DateTime.Now.Subtract(Start))); //Set progress bar only if valid if (pbStatus.Maximum >= SL.Frame) { pbStatus.Value = SL.Frame; } else { pbStatus.Value = pbStatus.Maximum; } }); } } } } P.WaitForExit(); } }) { IsBackground = true, Name = "Encoding of " + SourceFile }; Encoder.Start(); Tools.WatchThread(Encoder); }