Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WindowsConstants.au3>
- #include <GUIConstants.au3>
- #include <GDIP.au3>
- #include <WinAPI.au3>
- ; - Author: name22 (www.autoit.de)
- Opt("GUIOnEventMode", 1)
- ;###-v-SETTINGS-v-###
- $iGUIWidth = 720 ;Videobreite
- $iGUIHeight = 408 ;Videohöhe
- $iARGB_BG = 0x00000000 ;Hintergrundfarbe
- $nFPS = 30 ;Framerate (muss nicht der Framerate des Videos entsprechen!)
- $sInputVideo = @ScriptDir & "\Test 2.avi" ;Pfad zur Videodatei
- $sOutputFolder = @ScriptDir & "\Frames" ;Ausgabeverzeichnis der einzelnen Frames
- $iVideoLength = 8000 ;Videolänge in Millisekunden
- ;###-^-SETTINGS-^-###
- $tSize = DllStructCreate($tagSIZE)
- $pSize = DllStructGetPtr($tSize)
- DllStructSetData($tSize, "X", $iGUIWidth)
- DllStructSetData($tSize, "Y", $iGUIHeight)
- $tSource = DllStructCreate($tagPOINT)
- $pSource = DllStructGetPtr($tSource)
- $tBlend = DllStructCreate($tagBLENDFUNCTION)
- $pBlend = DllStructGetPtr($tBlend)
- DllStructSetData($tBlend, "Alpha", 255)
- DllStructSetData($tBlend, "Format", 1)
- $tPoint = DllStructCreate($tagPOINT)
- $pPoint = DllStructGetPtr($tPoint)
- DllStructSetData($tPoint, "X", 0)
- DllStructSetData($tPoint, "Y", 0)
- $iCurFrame = 1
- $nSleepTime = 1000 / $nFPS
- $nFPS_Display = 0
- $nFPS_Average = $nFPS
- $vNTdll = DllOpen("ntdll.dll")
- $tPrecSleep = DllStructCreate("int64 time;")
- $pPrecSleep = DllStructGetPtr($tPrecSleep)
- $hMain = GUICreate("Chroma Keying Example by name22", $iGUIWidth, $iGUIHeight, Default, Default, $WS_POPUP, $WS_EX_LAYERED)
- GUISetState()
- $hDC_Main = _WinAPI_GetDC($hMain)
- $hDC_Buffer = _WinAPI_CreateCompatibleDC($hDC_Main)
- $hBitmap_Buffer = _WinAPI_CreateCompatibleBitmap($hDC_Main, $iGUIWidth, $iGUIHeight)
- _WinAPI_SelectObject($hDC_Buffer, $hBitmap_Buffer)
- _GDIPlus_Startup()
- $hGraphics = _GDIPlus_GraphicsCreateFromHDC($hDC_Buffer)
- _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
- _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, 3)
- $hBrush_Black = _GDIPlus_BrushCreateSolid(0xFF000000)
- $hStringFormat = _GDIPlus_StringFormatCreate()
- $hFamily_FPS = _GDIPlus_FontFamilyCreate("Arial")
- $hFont_FPS = _GDIPlus_FontCreate($hFamily_FPS, 6)
- $aMeasure = _GDIPlus_GraphicsMeasureString($hGraphics, "FPS: 000", $hFont_FPS, _GDIPlus_RectFCreate(), $hStringFormat)
- $tLayout_FPS = $aMeasure[0]
- $aMeasure = ""
- DllStructSetData($tLayout_FPS, "X", $iGUIWidth - DllStructGetData($tLayout_FPS, "Width") - 3)
- DllStructSetData($tLayout_FPS, "Y", $iGUIHeight - DllStructGetData($tLayout_FPS, "Height"))
- DllStructSetData($tLayout_FPS, "Width", DllStructGetData($tLayout_FPS, "Width") + 3)
- GUISetOnEvent($GUI_EVENT_CLOSE, "_Close", $hMain)
- HotKeySet("{ESC}", "_Close")
- OnAutoItExitRegister("_Shutdown")
- If DirGetSize($sOutputFolder) = -1 Then DirCreate($sOutputFolder)
- RunWait(@ScriptDir & '\ffmpeg.exe -sameq -i "' & $sInputVideo & '" "' & $sOutputFolder & '\Frame %d.jpg"', @ScriptDir, @SW_HIDE, 0x2)
- $oFSO = ObjCreate("Scripting.FileSystemObject")
- $iFileCount = $oFSO.GetFolder($sOutputFolder).Files.Count
- Global $aFrames[$iFileCount + 1] = [$iFileCount]
- $hIA_Keying = _GDIPlus_ImageAttributesCreate()
- _GDIPlus_ImageAttributesSetColorKeys($hIA_Keying, 1, True, 0xFF454545, 0xFFFFFFFF)
- For $i = 1 To $aFrames[0]
- $aFrames[$i] = _GDIPlus_ImageLoadFromFile($sOutputFolder & "\Frame " & $i & ".jpg")
- ;~ $hGraphicsTmp = _GDIPlus_ImageGetGraphicsContext($aFrames[$i])
- ;Hier könnte noch ein Wasserzeichen o.Ä. eingefügt werden.
- ;~ _GDIPlus_GraphicsDispose($hGraphicsTmp)
- Next
- $nT_UpdateFPS = TimerInit()
- $nT_RunningTime = TimerInit()
- $nT_Sleep = TimerInit() + $nSleepTime
- While True
- DllStructSetData($tPrecSleep, "time", -10000 * ($nSleepTime - TimerDiff($nT_Sleep)))
- DllCall($vNTdll, "dword", "ZwDelayExecution", "int", 0, "ptr", $pPrecSleep)
- $nFrameTime = TimerDiff($nT_Sleep)
- $nT_Sleep = TimerInit()
- $nFPS_Cur = 1000 / $nFrameTime
- If TimerDiff($nT_UpdateFPS) >= 1000 Then
- $nFPS_Display = $nFPS_Cur
- $nT_UpdateFPS = TimerInit()
- EndIf
- _GDIPlus_GraphicsClear($hGraphics, $iARGB_BG)
- $iCurFrame = Ceiling(TimerDiff($nT_RunningTime) / $iVideoLength * $aFrames[0])
- If $iCurFrame > $aFrames[0] Then
- $iCurFrame = 1
- $nT_RunningTime = TimerInit()
- EndIf
- _GDIPlus_GraphicsDrawImageRectRectIA($hGraphics, $aFrames[$iCurFrame], 0, 0, $iGUIWidth, $iGUIHeight, 0, 0, $iGUIWidth, $iGUIHeight, $hIA_Keying)
- _GDIPlus_GraphicsDrawStringEx($hGraphics, "FPS: " & Int($nFPS_Display), $hFont_FPS, $tLayout_FPS, $hStringFormat, $hBrush_Black)
- _WinAPI_UpdateLayeredWindow($hMain, $hDC_Main, 0, $pSize, $hDC_Buffer, $pSource, 0, $pBlend, 2)
- WEnd
- Func _Close()
- Exit
- EndFunc ;==>_Close
- Func _Shutdown()
- _WinAPI_ReleaseDC($hMain, $hDC_Main)
- _WinAPI_DeleteDC($hDC_Buffer)
- _WinAPI_DeleteObject($hBitmap_Buffer)
- _GDIPlus_GraphicsDispose($hGraphics)
- For $i = 1 To $aFrames[0]
- _GDIPlus_ImageDispose($aFrames[$i])
- Next
- _GDIPlus_BrushDispose($hBrush_Black)
- _GDIPlus_StringFormatDispose($hStringFormat)
- _GDIPlus_FontFamilyDispose($hFamily_FPS)
- _GDIPlus_FontDispose($hFont_FPS)
- _GDIPlus_ImageAttributesDispose($hIA_Keying)
- _GDIPlus_Shutdown()
- DllClose($vNTdll)
- EndFunc ;==>_Shutdown
- ;Copyright name22 (@http://www.autoit.de/) Tuesday, 24th May 2011
- ; #FUNCTION#;===============================================================================
- ;
- ; Name...........: _HighPrecisionSleep()
- ; Description ...: Sleeps down to 0.1 microseconds
- ; Syntax.........: _HighPrecisionSleep( $iMicroSeconds, $hDll=False)
- ; Parameters ....: $iMicroSeconds - Amount of microseconds to sleep
- ; $hDll - Can be supplied so the UDF doesn't have to re-open the dll all the time.
- ; Return values .: None
- ; Author ........: Andreas Karlsson (monoceres)
- ; Modified.......:
- ; Remarks .......: Even though this has high precision you need to take into consideration that it will take some time for autoit to call the function.
- ; Related .......:
- ; Link ..........;
- ; Example .......; No
- ;
- ;;==========================================================================================
- Func _HighPrecisionSleep($iMicroSeconds, $hDll = False)
- Local $hStruct, $bLoaded
- If Not $hDll Then
- $hDll = DllOpen("ntdll.dll")
- $bLoaded = True
- EndIf
- $hStruct = DllStructCreate("int64 time;")
- DllStructSetData($hStruct, "time", -1 * ($iMicroSeconds * 10))
- DllCall($hDll, "dword", "ZwDelayExecution", "int", 0, "ptr", DllStructGetPtr($hStruct))
- If $bLoaded Then DllClose($hDll)
- EndFunc ;==>_HighPrecisionSleep
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement