Jump to content

gui active after running process


Go to solution Solved by ajenkins,

Recommended Posts

  • 3 weeks later...
  • Solution

The Solution to the key send was stdinwrite(). That combined with the changes from M23 solved all problems. Thanks M23 for all the help!

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <ProgressConstants.au3>
#include <Constants.au3>
#include <GuiEdit.au3>
#include <Date.au3>
#include <ButtonConstants.au3>


Global $fInterrupt = 0, $Button2, $Button3

gui1()
Func gui1()

    $Form1 = GUICreate("Form1", 615, 478, 192, 124)
    Global $Edit1 = GUICtrlCreateEdit("", 8, 16, 601, 289)
    GUICtrlSetData(-1, "Edit1")
    Global $Progress1 = GUICtrlCreateProgress(8, 320, 593, 33)
    Global $Progress2 = GUICtrlCreateProgress(8, 368, 601, 33)
    $Button1 = GUICtrlCreateButton("Start", 24, 432, 89, 25)
    $Button2 = GUICtrlCreateButton("next", 128, 432, 89, 25)
    $Button3 = GUICtrlCreateButton("Exit", 232, 432, 89, 25)
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $Button3
                exitprog()
            Case $Button1
                start()
        EndSwitch
    WEnd
EndFunc   ;==>gui1

Func start()
    $somefolder = FileSelectFolder("Select Encode Folder", "")
    $Afiles = _FileListToArray($somefolder)
    $sStdErr = ""
    $iTicksDuration = 0
    $iTicksTime = 0
    $ffmpeg = $somefolder & "\ffmpeg.exe"

    For $i = 1 To $Afiles[0]
        $file = $Afiles[$i]
        $hPid = Run($ffmpeg & ' -i "' & $file & '" -y "' & StringTrimRight($file, 4) & '_output.mp4"', $somefolder, @SW_HIDE, $STDIN_CHILD + $STDERR_CHILD)

        ; Get a timestamp
        $nBegin = TimerInit()

        While 1
            $nMsg = GUIGetMsg()
            Switch $nMsg
                Case $GUI_EVENT_CLOSE, $Button3
                    exitprog()
                Case $Button2
            StdinWrite($hPid, "q")
            EndSwitch

            ; Do this every 500 ms
            If TimerDiff($nBegin) > 500 Then
                $sStdErr &= $file & StderrRead($hPid)
                If @error Then ExitLoop
                GUICtrlSetData($Edit1, $sStdErr)
                If StringLen($sStdErr) > 0 Then
                    If Not $iTicksDuration Then $iTicksDuration = _GetDuration($sStdErr)
                    $iTicksTime = _GetTime($sStdErr)
                    If Not @error Then $sStdErr = ""
                    GUICtrlSetData($Progress1, $iTicksTime * 100 / $iTicksDuration)
                EndIf
                ; Reset the timer
                $nBegin = TimerInit()
            EndIf

        WEnd
        ProgressOff()
        GUICtrlSetData($Progress2, ($i / $Afiles[0]) * 100)
    Next
EndFunc   ;==>start

Func _GetDuration($sStdErr)
    If Not StringInStr($sStdErr, "Duration:") Then Return SetError(1, 0, 0)
    Local $aRegExp = StringRegExp($sStdErr, "(?i)Duration.+?([0-9:]+)", 3)
    If @error Or Not IsArray($aRegExp) Then Return SetError(1, 0, 0)
    Local $sTime = $aRegExp[UBound($aRegExp) - 1]
    Local $aTime = StringSplit($sTime, ":", 2)
    If @error Or Not IsArray($aTime) Then Return SetError(1, 0, 0)
    Return _TimeToTicks($aTime[0], $aTime[1], $aTime[2])
EndFunc   ;==>_GetDuration

Func _GetTime($sStdErr)
    If Not StringInStr($sStdErr, "time=") Then Return SetError(1, 0, 0)
    Local $aRegExp = StringRegExp($sStdErr, "(?i)time.+?([0-9:]+)", 3)
    If @error Or Not IsArray($aRegExp) Then Return SetError(1, 0, 0)
    Local $sTime = $aRegExp[UBound($aRegExp) - 1]
    Local $aTime = StringSplit($sTime, ":", 2)
    If @error Or Not IsArray($aTime) Then Return SetError(1, 0, 0)
    Return _TimeToTicks($aTime[0], $aTime[1], $aTime[2])
EndFunc   ;==>_GetTime

Func exitprog()
    If ProcessExists("ffmpeg.exe") Then
       ProcessClose("ffmpeg.exe")

    EndIf
    Exit
EndFunc   ;==>exitprog
Edited by ajenkins
Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...