nullschritt

[Solved] Trying to capture the webcam

3 posts in this topic

#1 ·  Posted (edited)

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

    $wm_cap_start = 1024
    $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

    Func _webcaminit()
        Global $avi = DllOpen("avicap32.dll")
        Global $user = DllOpen("user32.dll")
    EndFunc

    Func _webcam($gui, $w, $h, $l, $t)
        Global $cap = DllCall($avi, "int", "capCreateCaptureWindow", "str", "cap", "int", BitOR($ws_child, $ws_visible), "int", $l, "int", $t, "int", $w, "int", $h, "hwnd", $gui, "int", 1)
        DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $wm_cap_driver_connect, "int", 0, "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)
        Return $cap
    EndFunc

    Func _webcamstop()
        DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $wm_cap_end, "int", 0, "int", 0)
        DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $wm_cap_driver_disconnect, "int", 0, "int", 0)
        DllClose($user)
        DllClose($avi)
    EndFunc

    Func _webcamsnapshot($file = $snapfile)
        DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $wm_cap_grab_frame_nostop, "int", 0, "int", 0)
        DllCall($user, "int", "SendMessage", "hWnd", $cap[0], "int", $wm_cap_file_savediba, "int", 0, "str", $file)
     EndFunc

     Global $broadcastgui = GUICreate("Video", 320, 260)
        _webcaminit()
        Global $camcontrol = _webcam($broadcastgui, 320, 240, 0, 0)
        GUISetState(@SW_SHOW)

        while 1
           if GUIGetMsg() = $GUI_EVENT_CLOSE then Exit
        sleep(10)
        WEnd
 

Hello friends, I have some code here that previously worked flawlessly, on an older version of autoit, but on trying it with the latest version it doesn;t quite function as expected.

I'm trying to make a webcam capture window, and the script seems to work fine up until it comes to displaying the camera.

It will pop up and ask me which camera I want to use, but then when I push okay, the camera control is created on the windows, but it remains black and my webcam indicator light doesnt turn on.

Any solutions would be helpful, thanks ahead of time.

and my code:

 

Edited by nullschritt

Share this post


Link to post
Share on other sites



Solved by changing to the ESCAPI to capture the frames.

Share this post


Link to post
Share on other sites

#3 ·  Posted

On 3/9/2015 at 1:29 AM, nullschritt said:

Solved by changing to the ESCAPI to capture the frames.

Can you share an example please? Thank you!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now