fatpig Posted October 28, 2012 Share Posted October 28, 2012 Hey guys, I have been working on an automation app for ffmpeg.exe recently. It all works nicely, ffmpeg.exe is a command line tool to encode video files. while it is working, it gives me the current position of the encode in the format 00:01:02:77 (hours, minutes, seconds, percent of a second) I also have the duration of the video. this is used to calculate the percentage already encoded. trouble is, even if i let it run without any "sleep", it never catches the last message which would display the total time of the video as the current position, which would be 100%, it gets worse the shorter the video is. My question is, is there any option to get the "exit" message of a window, so to say, the absolute last stderr read? I need this so it is not confusing and so I can know if the ffmpeg.exe terminated somewhere in between. thoughts? Thanks! Link to comment Share on other sites More sharing options...
Developers Jos Posted October 28, 2012 Developers Share Posted October 28, 2012 Can you show the code section you use to capture the STDOUT/STDERR to see if that is correct? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
fatpig Posted October 28, 2012 Author Share Posted October 28, 2012 Oh, of course. It may be a bit confusing, I am still learning expandcollapse popup$runbefehl = """" & @scriptdir & "ffmpeg.exe" & """" & " -i " & """" & $sourcearray2[$i] & """" & " -y -target " & $system & "-dvd -b:v " & $bitrate & "k -aspect " & $aspect& " " & """" & $destination & "output" & $i & ".mpg" & """" ;~ InputBox("","",$runbefehl) $process = run($runbefehl, @ScriptDir, @SW_HIDE, $STDERR_CHILD) WinWait(@scriptdir & "ffmpeg.exe") $counterprogress = 0 sleep(100) ;~ while 1 $line = StderrRead($process) ;stderr lesen ;~ if @error Then ExitLoop ;~ WEnd ;~ InputBox("","",$line) ;~ =============================================================progress auslesen While WinExists(@scriptdir & "ffmpeg.exe") $lineshort = StringRight($line, 200) ;~ inputbox("","",$line) ; DEBUG LINE ;~ MsgBox(64,"",$curtime) sleep(10) If GUICtrlRead($Cancel) = 1 Then ProcessClose($process) EndIf If $lineshort = "" Then Else Do $curtime = StringRight($lineshort, $counterprogress) ; hier progress auslesen $counterprogress = $counterprogress + 1 Until Stringinstr($curtime, "time=") $counterprogress = 0 $curtime = StringTrimLeft($curtime, 5) Do $curtime = StringTrimRight($curtime, 1) until StringInStr($curtime, " ") = 0 ;~ GUICtrlSetData($statusbox, "begin transcoding… (step 1 of 2)" & @crlf & $curtime & " of " & $duration) $HourCur = Stringleft($curtime, 2) ;~ msgbox(64,"",$curtime) $MinCur = StringTrimLeft(StringLeft($curtime, 5),3) $SecCur = StringTrimLeft(StringLeft($curtime, 8),6) ;~ ===============================================================times to ticks Local $TotalTicks = $runtimearray[$i] Local $CurrentTicks = _TimeToTicks($HourCur, $MinCur, $SecCur) ; current time to ticks ;~ ===============================================================calulate percentage $percent = Round($CurrentTicks / ($TotalTicks / 100), 0) ;~ msgbox(64,"",$percent) GUICtrlSetData($progress, $percent) GUICtrlSetData($percentagelabel, $percent & Chr(37)) ;~ =============================================================== ;~ END CALCULATING PERCENTAGE ;~ =============================================================== EndIf Link to comment Share on other sites More sharing options...
Developers Jos Posted October 28, 2012 Developers Share Posted October 28, 2012 2 questions about your code: 1. Where do you read the STDERR inside the While-Wend loop as I do not see it in the code? 2. You loop base on WinExists() with the program... why ? Think that loop should continue until StderrRead() returns an @error to ensure you capture all output. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
fatpig Posted October 28, 2012 Author Share Posted October 28, 2012 Hello, I think you got the gist of the problem there. I do not fully understand how to do it the best way. it did it by winexists() because I did not fully understand the construction between stderrread and the while loop. currently I am doing it by winexists, and every loop it reads stderr by $line = StderrRead($process) are you saying, that a while 1 loop with an @error exit line like you said, would be equal to a winexists() function, but more accurate? Link to comment Share on other sites More sharing options...
Developers Jos Posted October 28, 2012 Developers Share Posted October 28, 2012 (edited) Correct, I would expect the script to look something like: While 1 ; add latest STDERR to $line $line &= StderrRead($process) ;stderr lesen if @error Then ExitLoop ; Exit when STDERR fails which mean that the process doesn't exist anymore $lineshort = StringRight($line, 200) ; ... rest of your while loop Edited October 28, 2012 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
fatpig Posted October 28, 2012 Author Share Posted October 28, 2012 Thank you very much. Great help! I will try that! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now