Jump to content

Can't get data from STDOUT


Go to solution Solved by InnI,

Recommended Posts

I need to get the length of a video file in seconds.

I decided to use ffprobe.exe    (ffmpeg) 

https://superuser.com/questions/650291/how-to-get-video-duration-in-seconds/945604#945604  

The command $startLine should only return a number, but mine is empty.

i8UizZU.jpg

#include <File.au3>
#include <ProcessConstants.au3>
#include <WinAPIProc.au3>
#include <WinAPISys.au3>

GetFileDuration()

Func GetFileDuration()
    $startLine = '"e:\ffprobe.exe" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 t:\111.mp4'
    $iPID = Run($startLine, "", @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD))
    If _WinAPI_GetVersion() >= 6.0 Then
        $hProcess = _WinAPI_OpenProcess($PROCESS_QUERY_LIMITED_INFORMATION, 0, $iPID)
    Else
        $hProcess = _WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION, 0, $iPID)
    EndIf
    $sOutput = ""
    While 1
        $sOutput = StderrRead($iPID)
        If @error Then
            ExitLoop
        ElseIf $sOutput <> "" Then
            ConsoleWrite($sOutput & @CRLF) ;### Debug Console
        EndIf
        Sleep(100)
    WEnd
    ProcessWaitClose($iPID)
    $ExitCode = DllCall("kernel32.dll", "bool", "GetExitCodeProcess", "HANDLE", $hProcess, "dword*", -1)
    _WinAPI_CloseHandle($hProcess)
EndFunc

If simplify the command and remove the keys, then I see the data, but the prime number does not.

"e:\ffprobe.exe"  t:\111.mp4

What am I doing wrong?

mAyDlSl.jpg

0YizAI1.jpg

Link to post
Share on other sites

Try this...

$startLine = 'e:\ffprobe.exe "-v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 t:\111.mp4"'

Not tested, but should work.

 

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to post
Share on other sites

okay, so it's telling you that you have a "missing argument" in your string.

I'm not familiar with what should be in the string and what should not.

 

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to post
Share on other sites

You can also try this, if the one above doesn't work...

$startLine = 'e:\ffprobe.exe "-v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1" t:\111.mp4'

 

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to post
Share on other sites

Does your string work from a Windows command window?

 

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to post
Share on other sites

Good catch. I must be slipping not to notice that.

 

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to post
Share on other sites
  • 3 weeks later...

I'd like to recommend to "bundle" STDERR" and "STDOUT"

$Exe="E:\ffprobe.exe"
$Params=" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 t:\111.mp4"

$PID = Run($Exe & $Params,@TempDir,@SW_SHOW,$STDERR_MERGED)

While ProcessExists ($PID)
    Sleep(500)
WEnd

$Result=StdoutRead($PID)
MsgBox(0, '', $Result)

 

As ffprobe.exe seems to be a command line tool it should be possible to paralellize the processing, QND and not tested at all, derived from some other script, just to give you a start:

#include <Debug.au3>
#include <File.au3>


$aMP4 = _FileListToArrayRec("C:\temp", "*.MP4", 1, 1, 0, 2)

_DebugArrayDisplay($aMP4)

$Exe = "E:\ffprobe.exe"
$Str4ArrayAdd = ""

For $i = 1 To $aMP4[0]
    $Params = ' -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "' & $aMP4[$i] & '"'
    $PID = Run($Exe & $Params, @TempDir, @SW_SHOW, $STDERR_MERGED)
    $Str4ArrayAdd &= $PID & "|" & $aMP4[$i] & @CRLF
Next
; cut off final @crlf
$Str4ArrayAdd = StringTrimRight($Str4ArrayAdd, 2)

Dim $a2MP4andPID[1][2]
_ArrayAdd($a2MP4andPID, $Str4ArrayAdd)
$a2MP4andPID[0][0] = UBound($a2MP4andPID) - 1


$StrResult = ""
Do
    $ProcCount = 0
    For $p = UBound($a2MP4andPID) - 1 To 1 Step -1
        If ProcessExists($a2MP4andPID[$p][0]) Then
            $ProcCount += 1
        Else
            $result = StdoutRead($PID)
            $StrResult &= $result & "|" & $a2MP4andPID[$p][1] & @CRLF
            _ArrayDelete($a2MP4andPID, $p)
        EndIf
    Next
    ToolTip($ProcCount & " Processes remaining...", 100, 100)
Until $ProcCount = 0
ToolTip("")

$StrResult = StringTrimRight($StrResult, 2)

Dim $a2Results[1][2]
_ArrayAdd($a2Results, $StrResult)
$a2Results[0][0] = UBound($a2Results) - 1

_ArraySort($a2Results, 1, 1) ; sort descending by size
_DebugArrayDisplay($a2Results)

 

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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...