[FFmpeg-user] [Windows] Running ffmpeg.exe programatically - possible to monitor progress?

Mark Richards mark at richardsemail.net
Fri Feb 10 14:27:46 CET 2012


> If my Win32 app launches ffmpeg.exe with a command-line, does anyone 
> know if there is a way to monitor the progress and when it has 
> finished?

It's actually pretty easy.  Create a Process, give it all the info to run
ffmpeg, then let it run async, and monitor StandardError (For some reason
ffmpeg writes to standarderror instead of standardOut).  Here's a snippet of
VB.Net code I use.

            myProcess = New System.Diagnostics.Process()
            myProcess.StartInfo.FileName = FFMPEGPath
            myProcess.StartInfo.Arguments = CommandLine
            myProcess.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Hidden
            myProcess.StartInfo.UseShellExecute = False
            myProcess.StartInfo.RedirectStandardOutput = True
            myProcess.StartInfo.RedirectStandardError = True
            myProcess.StartInfo.ErrorDialog = False
            myProcess.StartInfo.CreateNoWindow = True
            myProcess.StartInfo.RedirectStandardInput = True

	myProcess.Start()

            While Not myProcess.HasExited

                S = myProcess.StandardError.ReadLine()
                standardError.Append(vbCrLf & S)
                'myProcess.StandardError.DiscardBufferedData()

                If Now.ToUniversalTime.Subtract(LastEvent).TotalSeconds >
IntervalSeconds Then
                    Dim i As Integer = S.LastIndexOf("time=")
                    If i > 0 Then
                        Try
                            Dim SS As String = S.Substring(i + 5,
S.IndexOf(" ", i) - i - 5)
                            If IsNumeric(SS) Then
                                Dim T As Single = CSng(SS)
                                Dim P As Single = T / VI.VI.Duration
                                If P > 1 Then P = 1
                                RaiseEvent EncodingStatusUpdate(UniqueID, P)
                                cnt += 1
                            Else
                                Dim T As TimeSpan
                                If TimeSpan.TryParse(SS, T) Then
                                    Dim P As Single = T.TotalSeconds /
VI.VI.Duration
                                    If P > 1 Then P = 1
                                    RaiseEvent
EncodingStatusUpdate(UniqueID, P)
                                    cnt += 1
                                End If
                            End If

                        Catch ex As Exception
                        End Try
                        LastEvent = Now.ToUniversalTime
                    End If
                End If
            End While

            standardError.Append(myProcess.StandardError.ReadToEnd())
            standardOutput.Append(myProcess.StandardOutput.ReadToEnd())
            RaiseEvent EncodingStatusUpdate(UniqueID, 1)



More information about the ffmpeg-user mailing list