ludocus Posted May 9, 2008 Share Posted May 9, 2008 (edited) Made a udf to rysiora's webcam example, Webcam.au3 (the udf) expandcollapse popup#include <WindowsConstants.au3> #include-once $WM_CAP_START = 0x400 $WM_CAP_UNICODE_START = $WM_CAP_START +100 $WM_CAP_PAL_SAVEA = $WM_CAP_START + 81 $WM_CAP_PAL_SAVEW = $WM_CAP_UNICODE_START + 81 $WM_CAP_UNICODE_END = $WM_CAP_PAL_SAVEW $WM_CAP_ABORT = $WM_CAP_START + 69 $WM_CAP_DLG_VIDEOCOMPRESSION = $WM_CAP_START + 46 $WM_CAP_DLG_VIDEODISPLAY = $WM_CAP_START + 43 $WM_CAP_DLG_VIDEOFORMAT = $WM_CAP_START + 41 $WM_CAP_DLG_VIDEOSOURCE = $WM_CAP_START + 42 $WM_CAP_DRIVER_CONNECT = $WM_CAP_START + 10 $WM_CAP_DRIVER_DISCONNECT = $WM_CAP_START + 11 $WM_CAP_DRIVER_GET_CAPS = $WM_CAP_START + 14 $WM_CAP_DRIVER_GET_NAMEA = $WM_CAP_START + 12 $WM_CAP_DRIVER_GET_NAMEW = $WM_CAP_UNICODE_START + 12 $WM_CAP_DRIVER_GET_VERSIONA = $WM_CAP_START + 13 $WM_CAP_DRIVER_GET_VERSIONW = $WM_CAP_UNICODE_START + 13 $WM_CAP_EDIT_COPY = $WM_CAP_START + 30 $WM_CAP_END = $WM_CAP_UNICODE_END $WM_CAP_FILE_ALLOCATE = $WM_CAP_START + 22 $WM_CAP_FILE_GET_CAPTURE_FILEA = $WM_CAP_START + 21 $WM_CAP_FILE_GET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 21 $WM_CAP_FILE_SAVEASA = $WM_CAP_START + 23 $WM_CAP_FILE_SAVEASW = $WM_CAP_UNICODE_START + 23 $WM_CAP_FILE_SAVEDIBA = $WM_CAP_START + 25 $WM_CAP_FILE_SAVEDIBW = $WM_CAP_UNICODE_START + 25 $WM_CAP_FILE_SET_CAPTURE_FILEA = $WM_CAP_START + 20 $WM_CAP_FILE_SET_CAPTURE_FILEW = $WM_CAP_UNICODE_START + 20 $WM_CAP_FILE_SET_INFOCHUNK = $WM_CAP_START + 24 $WM_CAP_GET_AUDIOFORMAT = $WM_CAP_START + 36 $WM_CAP_GET_CAPSTREAMPTR = $WM_CAP_START + 1 $WM_CAP_GET_MCI_DEVICEA = $WM_CAP_START + 67 $WM_CAP_GET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 67 $WM_CAP_GET_SEQUENCE_SETUP = $WM_CAP_START + 65 $WM_CAP_GET_STATUS = $WM_CAP_START + 54 $WM_CAP_GET_USER_DATA = $WM_CAP_START + 8 $WM_CAP_GET_VIDEOFORMAT = $WM_CAP_START + 44 $WM_CAP_GRAB_FRAME = $WM_CAP_START + 60 $WM_CAP_GRAB_FRAME_NOSTOP = $WM_CAP_START + 61 $WM_CAP_PAL_AUTOCREATE = $WM_CAP_START + 83 $WM_CAP_PAL_MANUALCREATE = $WM_CAP_START + 84 $WM_CAP_PAL_OPENA = $WM_CAP_START + 80 $WM_CAP_PAL_OPENW = $WM_CAP_UNICODE_START + 80 $WM_CAP_PAL_PASTE = $WM_CAP_START + 82 $WM_CAP_SEQUENCE = $WM_CAP_START + 62 $WM_CAP_SEQUENCE_NOFILE = $WM_CAP_START + 63 $WM_CAP_SET_AUDIOFORMAT = $WM_CAP_START + 35 $WM_CAP_SET_CALLBACK_CAPCONTROL = $WM_CAP_START + 85 $WM_CAP_SET_CALLBACK_ERRORA = $WM_CAP_START + 2 $WM_CAP_SET_CALLBACK_ERRORW = $WM_CAP_UNICODE_START + 2 $WM_CAP_SET_CALLBACK_FRAME = $WM_CAP_START + 5 $WM_CAP_SET_CALLBACK_STATUSA = $WM_CAP_START + 3 $WM_CAP_SET_CALLBACK_STATUSW = $WM_CAP_UNICODE_START + 3 $WM_CAP_SET_CALLBACK_VIDEOSTREAM = $WM_CAP_START + 6 $WM_CAP_SET_CALLBACK_WAVESTREAM = $WM_CAP_START + 7 $WM_CAP_SET_CALLBACK_YIELD = $WM_CAP_START + 4 $WM_CAP_SET_MCI_DEVICEA = $WM_CAP_START + 66 $WM_CAP_SET_MCI_DEVICEW = $WM_CAP_UNICODE_START + 66 $WM_CAP_SET_OVERLAY = $WM_CAP_START + 51 $WM_CAP_SET_PREVIEW = $WM_CAP_START + 50 $WM_CAP_SET_PREVIEWRATE = $WM_CAP_START + 52 $WM_CAP_SET_SCALE = $WM_CAP_START + 53 $WM_CAP_SET_SCROLL = $WM_CAP_START + 55 $WM_CAP_SET_SEQUENCE_SETUP = $WM_CAP_START + 64 $WM_CAP_SET_USER_DATA = $WM_CAP_START + 9 $WM_CAP_SET_VIDEOFORMAT = $WM_CAP_START + 45 $WM_CAP_SINGLE_FRAME = $WM_CAP_START + 72 $WM_CAP_SINGLE_FRAME_CLOSE = $WM_CAP_START + 71 $WM_CAP_SINGLE_FRAME_OPEN = $WM_CAP_START + 70 $WM_CAP_STOP = $WM_CAP_START + 68 #include <GUIConstants.au3> $avi = DllOpen("avicap32.dll") $user = DllOpen("user32.dll") ;=============================================================================== ; ; Description: Open's a webcam preview screen in your gui ; Syntax: _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight, $sPort=0) ; Parameter(s): $sHwnd - The handle of the gui ; $sLeft - Left coord. of the preview screen ; $sTop - Top coord. of the preview screen ; $sWidth - Width of the preview screen ; $sHeight - Height of the preview screen ; $sPort - Specify wich webcam port you want to use (for multiple webcams) ; Requirement(s): A webcam ; Return Value(s): On Success - Returns id needed for other controls ; On Failure - Returns -1 ; Author(s): Ludocus ; Note(s): If a black/blank screen shows up, try using different $sPort's (0 to 3) ; ;=============================================================================== Func _WebcamOpen($sHwnd, $sLeft, $sTop, $sWidth, $sHeight, $sPort=0) $cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($WS_CHILD,$WS_VISIBLE), "int", $sLeft, "int", $sTop, "int", $sWidth, "int", $sHeight, "hwnd", $sHwnd, "int", 1) DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_DRIVER_CONNECT, "int", $sPort, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_SCALE, "int", 1, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_OVERLAY, "int", 1, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEW, "int", 1, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $WM_CAP_SET_PREVIEWRATE, "int", 1, "int", 0) if @error then return -1 return $cap[0] EndFunc ;=============================================================================== ; ; Description: Creates a Snapshot from a webcam ; Syntax: _WebcamSnap($sId, $sFile) ; Parameter(s): $sId - Id (returned from _WebcamOpen) ; $sFile - File to save the snapshot to (*.bmp) ; Requirement(s): A webcam ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; Author(s): Ludocus ; Note(s): None ; ;=============================================================================== Func _WebcamSnap($sId, $sFile) DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_SET_CALLBACK_FRAME, "int", 0, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_GRAB_FRAME_NOSTOP, "int", 0, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SAVEDIBA, "int", 0, "str", $sFile) if @error Then return 0 Else return 1 EndIf EndFunc ;=============================================================================== ; ; Description: Closes the preview screen created with _WebcamOpen ; Syntax: _WebcamClose($sId) ; Parameter(s): $sId - Id (returned from _WebcamOpen) ; Requirement(s): A webcam ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; Author(s): Ludocus ; Note(s): None ; ;=============================================================================== Func _WebcamClose($sId) DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_END, "int", 0, "int", 0) DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_DRIVER_DISCONNECT, "int", 0, "int", 0) DllClose($user) if @error Then return 0 Else return 1 EndIf EndFunc ;=============================================================================== ; ; Description: Starts recording the webcam to a file ; Syntax: _WebcamRecordStart($sFile, $sId) ; Parameter(s): $sId - Id (returned from _WebcamOpen) ; $sFile - File to save the movie to (*.avi) ; Requirement(s): A webcam ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; Author(s): Ludocus ; Note(s): Stop recording by: _WebcamRecordStop($Id) ; ;=============================================================================== Func _WebcamRecordStart($sFile, $sId) DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_FILE_SET_CAPTURE_FILEA, "int", 0, "str", $sFile) DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_SEQUENCE, "int", 0, "int", 0) if @error Then return 0 Else return 1 EndIf EndFunc ;=============================================================================== ; ; Description: Stops recording. ; Syntax: _WebcamRecordStop($sId) ; Parameter(s): $sId - Id (returned from _WebcamOpen) ; Requirement(s): A webcam ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; Author(s): Ludocus ; Note(s): None ; ;=============================================================================== Func _WebcamRecordStop($sId) DllCall($user, "int", "SendMessage", "hWnd", $sId, "int", $WM_CAP_STOP, "int", 0, "int", 0) if @error Then return 0 Else return 1 EndIf EndFunc thnx to rysiora with his great example! Edited February 25, 2011 by ludocus AutoBert and mLipok 2 Link to comment Share on other sites More sharing options...
ludocus Posted May 9, 2008 Author Share Posted May 9, 2008 Please Comment Link to comment Share on other sites More sharing options...
Kip Posted May 15, 2008 Share Posted May 15, 2008 This is already done. And better.http://www.autoitscript.com/forum/index.ph...;hl=Webcam++UDf MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
ludocus Posted May 23, 2008 Author Share Posted May 23, 2008 (edited) why do you say: 'and better'? Mine has a better discription + _WebcamRecordStart + _WebcamRecordStop + His udf has an error, Mine works with an Id Returned, His doesn't wich explains the error ?? I don't get the clue, what is worse about mine? Edited May 23, 2008 by ludocus Link to comment Share on other sites More sharing options...
EvAsion Posted May 23, 2008 Share Posted May 23, 2008 Everything |-- Periodic Table --||-- Dynamic Class Timetable --||-- Navigation in Counter-Strike --| Link to comment Share on other sites More sharing options...
ludocus Posted May 23, 2008 Author Share Posted May 23, 2008 (edited) could you be a little more clear? If there are some things wrong, then I would like to try to make them better. thnx Edited May 23, 2008 by ludocus jvds 1 Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted May 23, 2008 Share Posted May 23, 2008 Looks good, I may actually use it to make a log of everyone that uses my computer . Link to comment Share on other sites More sharing options...
jvanegmond Posted May 23, 2008 Share Posted May 23, 2008 Look in the original topic of how to use the webcam, and check for my post. It shows how to call the webcam, only without using the GUI that comes with it.Also, try to thank the original author inside the code as well. Someone may find your code in a location other then this, and he would think you made it completely, because that is what you state. github.com/jvanegmond Link to comment Share on other sites More sharing options...
StAbb Posted June 26, 2008 Share Posted June 26, 2008 Nice job man thanks! Link to comment Share on other sites More sharing options...
dmoniac Posted July 4, 2008 Share Posted July 4, 2008 Hi. I've a compil error on $WS_CHILD. I need to add : '#include <WindowsConstants.au3>' to fix it. Now, it run perfectly. muttley Link to comment Share on other sites More sharing options...
spudw2k Posted September 3, 2008 Share Posted September 3, 2008 (edited) Any idea why I get unpredictable recording lengths. What's the best practice to record for a speficied length of time? Edited September 3, 2008 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF  Link to comment Share on other sites More sharing options...
joseLB Posted December 16, 2008 Share Posted December 16, 2008 Hi, It didn't work with my webcam. I don't know what brand is it. The screen does not show up. Compilation was OK. Could you please provide a program example? Regards Jose Link to comment Share on other sites More sharing options...
ynbIpb Posted March 31, 2009 Share Posted March 31, 2009 (edited) Example:#include <GUIConstants.au3>#include <Webcam.au3>$gui = GUICreate("Test",322,242)$camera = _WebcamOpen($gui,1,1,320,240)GUISetState(@SW_SHOW)While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then _WebcamClose($camera) Exit EndIf Sleep(100)WEndludocus, you can refine the UDF, to be able to specify what parameters to run the camera? (I like the program, which goes along with the driver is given resolution, and frame rate.) And in the UDF is run with default settings? Edited March 31, 2009 by ynbIpb Link to comment Share on other sites More sharing options...
VAG Posted July 23, 2009 Share Posted July 23, 2009 May I know is it possible to adjust the quality settings of webcam (eg. brightness, contrast, gamma, etc) and is there any way of reading back the different settings from the current webcam before I set it? Link to comment Share on other sites More sharing options...
elawady Posted November 1, 2009 Share Posted November 1, 2009 (edited) thank you it's a verygood UDF . but when i have 3 webcam how can i change between them? Edited November 1, 2009 by elawady Link to comment Share on other sites More sharing options...
elawady Posted November 1, 2009 Share Posted November 1, 2009 up Link to comment Share on other sites More sharing options...
ludocus Posted August 29, 2010 Author Share Posted August 29, 2010 I'm sorry for not replying. I haven't been online on these forums for about a year. But, no.. I'm wondering how to do that myself. I've got no clue on how to choose between more than 1 webcam. Link to comment Share on other sites More sharing options...
kokoilie Posted October 10, 2012 Share Posted October 10, 2012 can you please tell me how to choose 1 (out of 1) camera because to me it's showing only black? Link to comment Share on other sites More sharing options...
BrewManNH Posted October 11, 2012 Share Posted October 11, 2012 This UDF doesn't work on any OS above XP (meaning Vista/7/and probably 8). 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...
JScript Posted October 11, 2012 Share Posted October 11, 2012 This UDF doesn't work on any OS above XP (meaning Vista/7/and probably 8).This is true, but if you use the dll avicap32.dll from XP, as I use, works normally!Shows us that the dll of Windows 7 has some problem.JS http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! 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