JohnOne Posted September 12, 2014 Share Posted September 12, 2014 (edited) One again, maths is wrecking my head. I'm not lazy or stupid, I just have never been able to do it. I'm trying to calculate how much time a loop would need to Sleep() in order to capture a pre determined amount of images from screen per second. So if I want 20fps, how much time should I sleep between captures? here some code which might better explain. 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 $FramesPerSecond = 15 $Iterator = 1 ;Loop for approx one second $Timer = TimerInit() While TimerDiff($Timer) <= $OneSecond $Cap = _ScreenCapture_Capture($CaptureFolder & $Iterator & ".bmp", 0, 0, 100, 100) ;Just for file name $Iterator += 1 WEnd $aFiles = _FileListToArray($CaptureFolder, "*.bmp", 1) If @error Then ;Remove files and folders _RemoveDir() Exit EndIf ;Amount of images created $CURRENT_FPS = Int($aFiles[0]) MsgBox(0, "Files", "system is capturing " & $CURRENT_FPS & " per second") _RemoveDir() Exit _CaptureFrames() Func _CaptureFrames() ;Inthis function I need to calculate ;how much time I need to sleep between ;captures so I get apporx $FramesPerSecond ;files $Iterator = 1 $Timer = TimerInit() While TimerDiff($Timer) <= $OneSecond $Cap = _ScreenCapture_Capture($CaptureFolder & $Iterator & ".bmp", 0, 0, 100, 100) ;Just for file name $Iterator += 1 ;Some calculation involving $FramesPerSecond ;and $CURRENT_FPS Sleep(??) ;<#<#<#<#<#<#<#<#<#<#<#<#<#<# Here WEnd EndFunc ;==>_CaptureFrames 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 Edited September 12, 2014 by JohnOne 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...
Luigi Posted September 12, 2014 Share Posted September 12, 2014 (edited) 1 second have 1000 mili seconds. If you have 20 frames per second, just 1000 / 20 = 80. (if you use HEX calc). If you have 20 frames per second, just 1000 / 20 = 50. (if you use DEC calc). AdLibRegister("takeshot", 50) Maybe this?? Edited September 12, 2014 by Detefon JohnOne 1 Visit my repository Link to comment Share on other sites More sharing options...
JohnOne Posted September 12, 2014 Author Share Posted September 12, 2014 If I sleep 80 it appears to capture 11 images, so I'm not sure that is correct, but thanks anyway. Also, one machine might capture images faster than another, which is why I made a calc of how many images it gets in 1 second without a sleep. 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...
UEZ Posted September 12, 2014 Share Posted September 12, 2014 1 second have 1000 mili seconds. If you have 20 frames per second, just 1000 / 20 = 80. AdLibRegister("takeshot", 80) Maybe this?? 1000 / 20 = 80 1000 / 20 = 50 -> 20 frames every 50 milliseconds. Br, UEZ JohnOne 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...
BrewManNH Posted September 12, 2014 Share Posted September 12, 2014 Actually 1000/20 = 50, not 80. You'd also need to build into the delay the time it takes to actually take the screenshot, and subtract that from the 50. So if it takes 5ms to take the screen shot, you'd want to delay 45ms, that way it will sleep for 45, take the screen shot, sleep for another 45 lather/rinse/repeat. JohnOne 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
UEZ Posted September 12, 2014 Share Posted September 12, 2014 (edited) If I sleep 80 it appears to capture 11 images, so I'm not sure that is correct, but thanks anyway. Also, one machine might capture images faster than another, which is why I made a calc of how many images it gets in 1 second without a sleep. Sleep(x) is sleep(x) regardless of your machine. As BrewManNH said to take screenshots it takes some milliseconds. Br, UEZ Edited September 12, 2014 by UEZ JohnOne 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...
Luigi Posted September 12, 2014 Share Posted September 12, 2014 1000 / 20 = 80 1000 / 20 = 50 -> 20 frames every 50 milliseconds. Br, UEZ Oh! My calc be operate in HEX! Not DEC! This is error! asohaoshaos JohnOne 1 Visit my repository Link to comment Share on other sites More sharing options...
UEZ Posted September 12, 2014 Share Posted September 12, 2014 (edited) @JohnOne: You can do something like this here:$iFPS = 20 $fDelay = 1000 / $iFPS $iSeconds = 1 $iMaxFrames = $iSeconds * $iFPS $iCounter = 0 $iTimer = TimerInit() Do If TimerDiff($iTimer) > $fDelay Then ConsoleWrite("Took a screenshot" & @CRLF) $iTimer = TimerInit() $iCounter += 1 EndIf Until $iCounter = $iMaxFrames ConsoleWrite("Captured " & $iCounter & " frames" & @CRLF)Br,UEZ Edited September 12, 2014 by UEZ JohnOne 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 (edited) Sleep(x) is sleep(x) regardless of your machine. As BrewManNH said to take screenshots it takes some milliseconds. Br,UEZIt's what I was trying to do, taking so many screenshots per second to get the avarage time it takes to take 1. Edited September 12, 2014 by JohnOne 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...
Gianni Posted September 12, 2014 Share Posted September 12, 2014 (edited) it should be: calculate the time taken by one sccreenshot then multiply that time for the number of screenshots you want to take in one second then subtract from 1000 the result of the above calc and you get the spare time (total idle time) now divide the spare time for each screenshot and sleep for the resulting time (between each screenshot) Edited September 12, 2014 by Chimp JohnOne 1 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...
jchd Posted September 12, 2014 Share Posted September 12, 2014 Adlib to frame period will be more robust. JohnOne 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
JohnOne Posted September 12, 2014 Author Share Posted September 12, 2014 it should be: calculate the time taken by one sccreenshot then multiply that time for the number of screenshots you want to take in one second then subtract from 1000 the result of the above calc and you get the spare time (total idle time) now divide the spare time for each screenshot and sleep for the resulting time (between each screenshot) That sounds about right. But instead of "calculate the time taken by one sccreenshot" How do I get the average time it takes from 100 shots? #include <Array.au3> #include <Screencapture.au3> Local $aShots[100] For $i = 0 To 99 $Timer = TimerInit() _ScreenCapture_Capture("pic.bmp", 0, 0, 100, 100) $Diff = TimerDiff($Timer) $aShots[$i] = $Diff Next FileDelete("pic.bmp") _ArrayDisplay($aShots) ;get average of $aShots 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...
JohnOne Posted September 12, 2014 Author Share Posted September 12, 2014 (edited) Is this correct? ConsoleWrite(Ceiling(_AvarageScreenshotTime()) & @LF) Func _AvarageScreenshotTime() Local $aShots[100] For $i = 0 To 99 $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 99 $Total += ($aShots[$i]) Next $average = $Total / 100 Return $average EndFunc ;==>_AvarageScreenshotTime Edited September 12, 2014 by JohnOne 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...
JohnOne Posted September 12, 2014 Author Share Posted September 12, 2014 (edited) I have what I thought would be it, but this script creates mostly 13 images in a second, and sometimes 12. Never 14 or 15. 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 ;Some Calculations. $AvaerageShoTime = _AvarageScreenshotTime(200) $Calc1 = $AvaerageShoTime * $TargetFramesPerSecond $Calc2 = 1000 - $Calc1 $Sleep = $Calc2 / $TargetFramesPerSecond ;Loop for approx one second $Timer = TimerInit() While TimerDiff($Timer) <= $OneSecond $Cap = _ScreenCapture_Capture($CaptureFolder & $Iterator & ".bmp", 0, 0, 100, 100) ;Just for file name $Iterator += 1 Sleep($Sleep) 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 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 Is there something missing? Edited September 12, 2014 by JohnOne 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...
jdelaney Posted September 12, 2014 Share Posted September 12, 2014 (edited) Maybe it would be better to rapid fire as many screenshots as possible, and then logically delete some of the files until you get 20 fps. Then, you don't have to worry about timing averages, which will never be consistent enough to do anything with. #include <ScreenCapture.au3> #include <File.au3> $iTimer=TimerInit() $i = 1 While TimerDiff($iTimer)<1000 _ScreenCapture_Capture(@DesktopDir & "\screenshots\" & $i & ".bmp",0,0,100,100) $i+=1 WEnd $aFiles = _FileListToArray(@DesktopDir & "\screenshots\") $iTotal = UBound($aFiles)-1 $iDelete = $iTotal-20 If $iTotal/$iDelete > 2 Then $iDeleteSkips = Int($iTotal/$iDelete) ConsoleWrite($iTotal & " " & $iDelete & " " & $iDeleteSkips & @CRLF) For $i = $iDeleteSkips+1 To UBound($aFiles)-1 Step $iDeleteSkips FileDelete(@DesktopDir & "\screenshots\" & $i & ".bmp") Next EndIf super simple example...more cacluations are required to get exactly any amount of screenshots. Edited September 12, 2014 by jdelaney JohnOne 1 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
BrewManNH Posted September 12, 2014 Share Posted September 12, 2014 (edited) Here's a much better option, instead of saving the files every time through the loop, get the $hBMP handle and store it in an array. After you've taken all of your screen shots, then save them all to disk, this way the function doesn't have to waste time saving files before returning and can return as soon as possible. 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 = 0 ;Some Calculations. $AvaerageShoTime = _AvarageScreenshotTime(200) $Calc1 = $AvaerageShoTime * $TargetFramesPerSecond $Calc2 = 1000 - $Calc1 $Sleep = $Calc2 / $TargetFramesPerSecond ;Loop for approx one second $Timer = TimerInit() Global $aCap[1000] While TimerDiff($Timer) <= $OneSecond $aCap[$Iterator] = _ScreenCapture_Capture("", 0, 0, 100, 100) ;Just for file name $Iterator += 1 Sleep($Sleep) WEnd ReDim $aCap[$Iterator] For $I = 0 To UBound($aCap) - 1 _ScreenCapture_SaveImage($CaptureFolder & $I & ".bmp", $aCap[$I]) Next $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 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 You'll have to adjust your averagescreenshotime function to accomodate that method. I've gotten up to 50+ screenshots using this, and as low as 40. Edited September 12, 2014 by BrewManNH JohnOne 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Gianni Posted September 12, 2014 Share Posted September 12, 2014 (edited) I have what I thought would be it, but this script creates mostly 13 images in a second, and sometimes 12. Never 14 or 15. 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 ;Some Calculations. $AvaerageShoTime = _AvarageScreenshotTime(200) $Calc1 = $AvaerageShoTime * $TargetFramesPerSecond $Calc2 = 1000 - $Calc1 $Sleep = $Calc2 / $TargetFramesPerSecond ;Loop for approx one second $Timer = TimerInit() While TimerDiff($Timer) <= $OneSecond $Cap = _ScreenCapture_Capture($CaptureFolder & $Iterator & ".bmp", 0, 0, 100, 100) ;Just for file name $Iterator += 1 Sleep($Sleep) 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 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 Is there something missing? try Return $average instead of Return Floor($average) and it should shot 15 frames above is to be forgotten edit: ..... not always ....... ? Edited September 12, 2014 by Chimp JohnOne 1 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...
JohnOne Posted September 12, 2014 Author Share Posted September 12, 2014 Maybe it would be better to rapid fire as many screenshots as possible, and then logically delete some of the files until you get 20 fps. Then, you don't have to worry about timing averages, which will never be consistent enough to do anything with. #include <ScreenCapture.au3> #include <File.au3> $iTimer=TimerInit() $i = 1 While TimerDiff($iTimer)<1000 _ScreenCapture_Capture(@DesktopDir & "\screenshots\" & $i & ".bmp",0,0,100,100) $i+=1 WEnd $aFiles = _FileListToArray(@DesktopDir & "\screenshots\") $iTotal = UBound($aFiles)-1 $iDelete = $iTotal-20 If $iTotal/$iDelete > 2 Then $iDeleteSkips = Int($iTotal/$iDelete) ConsoleWrite($iTotal & " " & $iDelete & " " & $iDeleteSkips & @CRLF) For $i = $iDeleteSkips+1 To UBound($aFiles)-1 Step $iDeleteSkips FileDelete(@DesktopDir & "\screenshots\" & $i & ".bmp") Next EndIf super simple example...more cacluations are required to get exactly any amount of screenshots. Thanks. That's a reasonable idea, but will add a significant amount of load to the CPU. I'm of the xchool that even in the day of multicores ans loads of RAM's and great big HDD's It's still better you only use what you really need. 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...
Gianni Posted September 12, 2014 Share Posted September 12, 2014 Here's a much better option, instead of saving the files every time through the loop, get the $hBMP handle and store it in an array. After you've taken all of your screen shots, then save them all to disk, this way the function doesn't have to waste time saving files before returning and can return as soon as possible. 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 = 0 ;Some Calculations. $AvaerageShoTime = _AvarageScreenshotTime(200) $Calc1 = $AvaerageShoTime * $TargetFramesPerSecond $Calc2 = 1000 - $Calc1 $Sleep = $Calc2 / $TargetFramesPerSecond ;Loop for approx one second $Timer = TimerInit() Global $aCap[1000] While TimerDiff($Timer) <= $OneSecond $aCap[$Iterator] = _ScreenCapture_Capture("", 0, 0, 100, 100) ;Just for file name $Iterator += 1 Sleep($Sleep) WEnd ReDim $aCap[$Iterator] For $I = 0 To UBound($aCap) - 1 _ScreenCapture_SaveImage($CaptureFolder & $I & ".bmp", $aCap[$I]) Next $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 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 You'll have to adjust your averagescreenshotime function to accomodate that method. I've gotten up to 50+ screenshots using this, and as low as 40. your way takes nearly always 15 frames per second. just wondering if in that way all frames are buffered in memory? if so, will this limits the total amount of seconds of the whole "movie" or this problem will be managed by the system? JohnOne 1 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 Well, I had the same problem when I created the feature to capture the screen to an avi file in Windows Screenshooter. I used this technique (function Grab2AVI()) to get as close as possible to the fps: expandcollapse popup... Local $hBitmap_AVI, $hBitmap_AVI_TS, $hBmp_AVI_TS, $OldBMP Local $iLeft, $iRight, $iTop, $iBottom Local $hIcon, $aIcon Local $tCursor, $tInfo, $iCursor, $aCursor[5], $aIcon[6] Local $total_FPS = $rec_time * $fps, $fps_c = 1 Local $bInfinity = False If $rec_time = "Endless" Then $bInfinity = True $total_FPS = 0xFFFFFF EndIf Local Const $fc = 1000 / $fps Local Const $k32_dll = DllOpen("kernel32.dll") Local Const $u32_dll = DllOpen("user32.dll") Local Const $DC = _WinAPI_GetDC(0) Local Const $hDC = _WinAPI_CreateCompatibleDC($DC) ... Do $t = TimerInit() ;_ScreenCapture_Capture() reduced $OldBMP = DllCall($g32_dll, "handle", "SelectObject", "handle", $hDC, "handle", $hBmp_AVI) ;_WinAPI_SelectObject() DllCall($g32_dll, "bool", "BitBlt", "handle", $hDC, "int", 0, "int", 0, "int", $iW, "int", $iH, "handle", $DC, "int", $iLeft, "int", $iTop, "dword", $SRCCOPY) ;_WinAPI_BitBlt() If $cursor Then $tCursor = DllStructCreate($tagCURSORINFO) $iCursor = DllStructGetSize($tCursor) DllStructSetData($tCursor, "Size", $iCursor) DllCall($u32_dll, "bool", "GetCursorInfo", "ptr", DllStructGetPtr($tCursor)) $aCursor[1] = DllStructGetData($tCursor, "Flags") <> 0 $aCursor[2] = DllStructGetData($tCursor, "hCursor") $aCursor[3] = DllStructGetData($tCursor, "X") $aCursor[4] = DllStructGetData($tCursor, "Y") If $aCursor[1] Then $hIcon = DllCall($u32_dll, "handle", "CopyIcon", "handle", $aCursor[2]) $tInfo = DllStructCreate($tagICONINFO) DllCall($u32_dll, "bool", "GetIconInfo", "handle", $hIcon[0], "ptr", DllStructGetPtr($tInfo)) $aIcon[2] = DllStructGetData($tInfo, "XHotSpot") $aIcon[3] = DllStructGetData($tInfo, "YHotSpot") $aIcon[4] = DllStructGetData($tInfo, "hMask") DllCall($g32_dll, "bool", "DeleteObject", "handle", $aIcon[4]) DllCall($u32_dll, "bool", "DrawIcon", "handle", $hDC, "int", $aCursor[3] - $aIcon[2] - $iLeft, "int", $aCursor[4] - $aIcon[3] - $iTop, "handle", $hIcon[0]) DllCall($u32_dll, "bool", "DestroyIcon", "handle", $hIcon[0]) EndIf EndIf DllCall($g32_dll, "int", "GetDIBits", "handle", $hDC, "handle", $hBmp_AVI, "uint", 0, "uint", $iLines, "ptr", $pBits, "ptr", $pHeader, "uint", 0) ;_WinAPI_GetDIBits() DllCall($g32_dll, "handle", "SelectObject", "handle", $hDC, "handle", $OldBMP[0]) ;_WinAPI_SelectObject() DllCall($Avi32_Dll, "int", "AVIStreamWrite", "ptr", $AVI_File[1], "long", $AVI_File[2], "long", 1, "ptr", $pBits, "long", $iSize, "long", $AVIIF_KEYFRAME, "ptr*", 0, "ptr*", 0) $AVI_File[2] += 1 If Not $bInfinity Then $fps_c += 1 EndIf $td = $fc - TimerDiff($t) If $td > 0 Then DllCall($k32_dll, "none", "Sleep", "dword", $td) EndIf If $fps_c > $total_FPS Or $end_avi_cap Then ExitLoop EndIf Until False ... Br, UEZ JohnOne 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...
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