Gianni Posted September 12, 2014 Share Posted September 12, 2014 Can't you do something like this, without calculating that average thing: ;... ;Loop for approx one second $Timer = TimerInit() While TimerDiff($Timer) <= $OneSecond $hAnotherTimer = TimerInit() $Cap = _ScreenCapture_Capture($CaptureFolder & $Iterator & ".bmp", 0, 0, 100, 100) ;Just for file name $Iterator += 1 Sleep(1000 / $AimFrames - TimerDiff($hAnotherTimer)) WEnd ;... trancexx way gives best results on my test in that way the time of sleep is self calibrating expandcollapse popup#include <Screencapture.au3> #include <File.au3> ;Create a temp folder in script dir if it does not exist Const $CaptureFolder = @ScriptDir & "\capture\" If Not FileExists($CaptureFolder) Then DirCreate($CaptureFolder) EndIf ;Some variables Const $OneSecond = 1000 Const $TargetFramesPerSecond = 15 $Iterator = 1 ;Loop for approx one second $Timer = TimerInit() While TimerDiff($Timer) <= $OneSecond $hAnotherTimer = TimerInit() $Cap = _ScreenCapture_Capture($CaptureFolder & $Iterator & ".bmp", 0, 0, 100, 100) ;Just for file name $Iterator += 1 Sleep(1000 / $TargetFramesPerSecond - TimerDiff($hAnotherTimer)) ; <-- sleep time is self calibrating WEnd $aFiles = _FileListToArray($CaptureFolder, "*.bmp", 1) If @error Then ;Remove files and folders _RemoveDir() Exit MsgBox(0, 0, "Error") EndIf ;Amount of images created $CURRENT_FPS = Int($aFiles[0]) MsgBox(0, "Files", "Captured " & $CURRENT_FPS & " images in 1 second") _RemoveDir() Func _RemoveDir() FileDelete($CaptureFolder & "*") For $i = 1 To 10 $Removed = DirRemove($CaptureFolder) If $Removed Then ExitLoop EndIf Sleep(100) Next MsgBox(0, "Removed Folder", ($Removed = 1)) EndFunc ;==>_RemoveDir Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
trancexx Posted September 12, 2014 Share Posted September 12, 2014 So, it's this: ;Loop for approx one second $Timer = TimerInit() While TimerDiff($Timer) <= $OneSecond $hAnotherTimer = TimerInit() _ScreenCapture_Capture($CaptureFolder & $Iterator & ".bmp", 0, 0, 100, 100) ;Just for file name $Iterator += 1 $iSlpTime = 1000 / $TargetFramesPerSecond - TimerDiff($hAnotherTimer) If $iSlpTime < 10 Then ConsoleWrite("! Max FPS reached on your machine. TargetFramesPerSecond = " & $TargetFramesPerSecond & @CRLF) Sleep($iSlpTime) WEnd When the output becomes red first time then you have reached maximum FPS value that you can get with _ScreenCapture_Capture on your machine. After that the time it takes to take a pic is longer than needed to get wanted FPS rate, even without sleep. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
UEZ Posted September 12, 2014 Share Posted September 12, 2014 That's what I did in ($td = $fc - TimerDiff($t)). 1000 / $TargetFramesPerSecond is a constant and can be calculated outside the loop once. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
czardas Posted September 12, 2014 Share Posted September 12, 2014 (edited) You might be able to optimize the UDF functions by removing any code which is not needed for your specific task. I sometimes remove error checks (and conditional statements) that are not needed because I know exactly what I'm feeding into a function. Fine tuning is sometimes the only way to go! Edited September 12, 2014 by czardas trancexx 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Gianni Posted September 12, 2014 Share Posted September 12, 2014 That's what I did in ($td = $fc - TimerDiff($t)). 1000 / $TargetFramesPerSecond is a constant and can be calculated outside the loop once. Br, UEZ true, self calibrating as well.... only a little more complicated to follow for me the overall logic in that more complex listing Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
UEZ Posted September 12, 2014 Share Posted September 12, 2014 (edited) Yes, I tried to optimize the code by embedding _ScreenCapture_Capture() directly and removed unneeded lines. Looks complicated but it is the price you pay when you try to optimize the code. Br, UEZ Edited September 12, 2014 by UEZ czardas 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
JohnOne Posted September 12, 2014 Author Share Posted September 12, 2014 With this I'm getting consistently stable results up to 70 fps. expandcollapse popup#include <Screencapture.au3> #include <File.au3> Const $AimFrames = 15 ;Create a temp folder in script dir if it does not exist Const $CaptureFolder = @ScriptDir & "\capture\" If Not FileExists($CaptureFolder) Then DirCreate($CaptureFolder) EndIf $ShotTime = _AvarageScreenshotTime(100) $Tune = 1;$ShotTime / 1.2 For $n = 10 To 70 _Main($n, $ShotTime, $Tune) ;Sleep(1000) Next Func _Main($TargetFramesPerSecond, $AvaerageShotTime, $FineTune) ;Some variables Const $OneSecond = 1000 $Iterator = 1 ;Some Calculations. ;_Debug($AvaerageShotTime, "$AvaerageShotTime") $Calc1 = $AvaerageShotTime * $TargetFramesPerSecond ;_Debug($Calc1, "$Calc1") $Calc2 = 1000 - $Calc1 ;_Debug($Calc2, "$Calc2") $Calc3 = $Calc2 / $TargetFramesPerSecond ;;_Debug($Calc3, "$Calc3") $Sleep = Ceiling($Calc3 - $FineTune) ;_Debug($Sleep, "$Sleep") If $TargetFramesPerSecond >= 40 Then $AvaerageShotTime += 2 ElseIf $TargetFramesPerSecond >= 30 Then $AvaerageShotTime += 1 EndIf ;Loop for approx one second $Timer = TimerInit() While TimerDiff($Timer) <= $OneSecond ;$hAnotherTimer = TimerInit() $Cap = _ScreenCapture_Capture($CaptureFolder & $Iterator & ".bmp", 0, 0, 100, 100) ;Just for file name $Iterator += 1 ;Sleep(1000 / $TargetFramesPerSecond - TimerDiff($hAnotherTimer)) $sTimer = TimerInit() Do Until TimerDiff($sTimer) >= (1000 / $TargetFramesPerSecond) - $AvaerageShotTime ;Sleep(66 - 15) WEnd Local $aFiles = _FileListToArray($CaptureFolder, "*.bmp", 1) If @error Then ;Remove files and folders If Not _RemoveDir() Then Exit MsgBox(0, 0, "Error _RemoveDir") EndIf Exit MsgBox(0, 0, "Error _FileListToArray") EndIf ;Amount of images created $CURRENT_FPS = Int($aFiles[0]) ConsoleWrite("Target = " & $TargetFramesPerSecond & " - Captured " & $CURRENT_FPS & @LF) _RemoveDir() EndFunc ;==>_Main Func _Debug($val, $varname) ConsoleWrite($varname & " = " & $val & @LF) EndFunc ;==>_Debug Func _RemoveDir() FileDelete($CaptureFolder & "*") #cs For $i = 1 To 10 $Removed = DirRemove($CaptureFolder) If $Removed Then ExitLoop EndIf Sleep(100) Next Return ($Removed = 0) #ce EndFunc ;==>_RemoveDir Func _AvarageScreenshotTime($NunShots) Local $aShots[$NunShots] For $i = 0 To $NunShots - 1 $Timer = TimerInit() _ScreenCapture_Capture("pic.bmp", 0, 0, 100, 100) $Diff = TimerDiff($Timer) $aShots[$i] = $Diff Next FileDelete("pic.bmp") $Total = 0 For $i = 0 To $NunShots - 1 $Total += ($aShots[$i]) Next $average = $Total / $NunShots Return Floor($average) EndFunc ;==>_AvarageScreenshotTime AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
czardas Posted September 12, 2014 Share Posted September 12, 2014 Target = 10 - Captured 10 Target = 11 - Captured 11 Target = 12 - Captured 12 Target = 13 - Captured 13 Target = 14 - Captured 14 Target = 15 - Captured 15 Target = 16 - Captured 16 Target = 17 - Captured 17 Target = 18 - Captured 18 Target = 19 - Captured 19 Target = 20 - Captured 20 Target = 21 - Captured 21 Target = 22 - Captured 22 Target = 23 - Captured 23 Target = 24 - Captured 24 Target = 25 - Captured 25 Target = 26 - Captured 26 Target = 27 - Captured 27 Target = 28 - Captured 28 Target = 29 - Captured 29 Target = 30 - Captured 30 Target = 31 - Captured 31 Target = 32 - Captured 32 Target = 33 - Captured 33 Target = 34 - Captured 34 Target = 35 - Captured 35 Target = 36 - Captured 36 Target = 37 - Captured 37 Target = 38 - Captured 38 Target = 39 - Captured 39 Target = 40 - Captured 42 Target = 41 - Captured 43 Target = 42 - Captured 44 Target = 43 - Captured 45 Target = 44 - Captured 45 Target = 45 - Captured 47 Target = 46 - Captured 48 Target = 47 - Captured 50 Target = 48 - Captured 47 Target = 49 - Captured 52 Target = 50 - Captured 52 Target = 51 - Captured 54 Target = 52 - Captured 54 Target = 53 - Captured 55 Target = 54 - Captured 57 Target = 55 - Captured 57 Target = 56 - Captured 60 Target = 57 - Captured 61 Target = 58 - Captured 60 Target = 59 - Captured 63 Target = 60 - Captured 64 Target = 61 - Captured 65 Target = 62 - Captured 66 Target = 63 - Captured 67 Target = 64 - Captured 68 Target = 65 - Captured 68 Target = 66 - Captured 70 Target = 67 - Captured 72 Target = 68 - Captured 73 Target = 69 - Captured 74 Target = 70 - Captured 75 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
JohnOne Posted September 12, 2014 Author Share Posted September 12, 2014 That's not bad, perhaps the others with crazy fast machines might get similar result. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. 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