mike2003 Posted July 24, 2021 Posted July 24, 2021 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. #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?
ripdad Posted July 24, 2021 Posted July 24, 2021 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
mike2003 Posted July 24, 2021 Author Posted July 24, 2021 No Missing argument for option 'v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 t:\111.mp4'
ripdad Posted July 24, 2021 Posted July 24, 2021 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
ripdad Posted July 24, 2021 Posted July 24, 2021 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
mike2003 Posted July 25, 2021 Author Posted July 25, 2021 My command is correct, I don't need to change it. I need to get data.
ripdad Posted July 25, 2021 Posted July 25, 2021 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
Solution InnI Posted July 25, 2021 Solution Posted July 25, 2021 8 hours ago, mike2003 said: I need to get data You use StderrRead. Try to use StdoutRead. mike2003 1
ripdad Posted July 25, 2021 Posted July 25, 2021 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
Nine Posted July 25, 2021 Posted July 25, 2021 9 minutes ago, ripdad said: I must be slipping You mean sleeping, right ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
ripdad Posted July 25, 2021 Posted July 25, 2021 Or lack of it. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
rudi Posted August 12, 2021 Posted August 12, 2021 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: expandcollapse popup#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) mike2003 1 Earth is flat, pigs can fly, and Nuclear Power is SAFE!
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