@@ -31,9 +31,9 @@ public class FFmpegProcess {
3131 /// </summary>
3232 public event EventHandler InfoUpdated ;
3333 /// <summary>
34- /// Occurs when progress update is received through FFmpeg's output stream.
34+ /// Occurs when status update is received through FFmpeg's output stream.
3535 /// </summary>
36- public event ProgressUpdatedEventHandler ProgressUpdated ;
36+ public event StatusUpdatedEventHandler StatusUpdated ;
3737 /// <summary>
3838 /// Occurs when the process has terminated its work.
3939 /// </summary>
@@ -65,8 +65,6 @@ public string Output {
6565 private bool isFFmpeg ;
6666 private bool isStarted ;
6767 private CancellationTokenSource cancelWork ;
68- private List < KeyValuePair < DateTime , long > > progressHistory ;
69- private bool nestedProcess ;
7068
7169 /// <summary>
7270 /// Initializes a new instances of the FFmpegProcess class.
@@ -151,14 +149,12 @@ public CompletionStatus Run(string fileName, string arguments, bool isFFmpeg, bo
151149 Process P = new Process ( ) ;
152150 this . isFFmpeg = isFFmpeg ;
153151 WorkProcess = P ;
154- this . nestedProcess = nestedProcess ;
155152 output = new StringBuilder ( ) ;
156153 isStarted = false ;
157154 FileStreams = null ;
158155 FrameCount = 0 ;
159156 FileDuration = TimeSpan . Zero ;
160157 cancelWork = new CancellationTokenSource ( ) ;
161- progressHistory = new List < KeyValuePair < DateTime , long > > ( ) ;
162158 if ( Options == null )
163159 Options = new ProcessStartOptions ( ) ;
164160
@@ -193,7 +189,6 @@ public CompletionStatus Run(string fileName, string arguments, bool isFFmpeg, bo
193189
194190 isStarted = false ;
195191 cancelWork = null ;
196- progressHistory = null ;
197192 LastCompletionStatus = Result ;
198193 Completed ? . Invoke ( this , new CompletedEventArgs ( Result ) ) ;
199194 if ( ( Result == CompletionStatus . Error || Result == CompletionStatus . Timeout ) && Options . DisplayMode == FFmpegDisplayMode . ErrorOnly )
@@ -264,9 +259,8 @@ private void FFmpeg_DataReceived(object sender, DataReceivedEventArgs e) {
264259 isStarted = true ;
265260
266261 if ( isStarted && e . Data . StartsWith ( "frame=" ) ) {
267- FFmpegProgress ProgressInfo = FFmpegParser . ParseProgress ( e . Data ) ;
268- CalculateTimeLeft ( ProgressInfo ) ;
269- ProgressUpdated ? . Invoke ( this , new ProgressUpdatedEventArgs ( ProgressInfo ) ) ;
262+ FFmpegStatus ProgressInfo = FFmpegParser . ParseProgress ( e . Data ) ;
263+ StatusUpdated ? . Invoke ( this , new StatusUpdatedEventArgs ( ProgressInfo ) ) ;
270264 }
271265 }
272266 }
@@ -282,25 +276,6 @@ private void ParseFileInfo() {
282276 InfoUpdated ? . Invoke ( this , new EventArgs ( ) ) ;
283277 }
284278
285- /// <summary>
286- /// Calculates the time left.
287- /// </summary>
288- /// <param name="progress">An object containing the latest progress info.</param>
289- private void CalculateTimeLeft ( FFmpegProgress progress ) {
290- // progressHistory contains the last 10 progress values.
291- progressHistory . Add ( new KeyValuePair < DateTime , long > ( DateTime . Now , progress . Frame ) ) ;
292- if ( progressHistory . Count > 10 )
293- progressHistory . RemoveAt ( 0 ) ;
294- if ( progressHistory . Count > 1 ) {
295- TimeSpan SampleWorkTime = progressHistory . Last ( ) . Key - progressHistory . First ( ) . Key ;
296- long SampleWorkFrame = progressHistory . Last ( ) . Value - progressHistory . First ( ) . Value ;
297- double ProcessingFps = SampleWorkFrame / SampleWorkTime . TotalSeconds ;
298- long WorkLeft = FrameCount - progress . Frame ;
299- if ( WorkLeft > 0 )
300- progress . EstimatedTimeLeft = TimeSpan . FromSeconds ( WorkLeft / ProcessingFps ) ;
301- }
302- }
303-
304279 /// <summary>
305280 /// Gets the first video stream from FileStreams.
306281 /// </summary>
0 commit comments