|
Post by ventilo25 on Sept 10, 2017 14:56:11 GMT 1
Who could translate in GFA32 this little program written in VB (Webcam Video.exe)? It allows to capture a Webcam with DirectShow using two dll, DirectX.Capture.dll and DshowNET.dll. Source in Vb in the Zip. streaming-audio-video.zip (66.76 KB) Friendship to all! Ventilo25
|
|
|
Post by dragonjim on Sept 11, 2017 10:31:09 GMT 1
Hi, Had a look at the program and managed to convert much of it from the native VB.Net 3.0 (I think?). The sticking point was when it came to converting the VB.Net DirectX library calls into calls to the DirectX dlls (the libraries you mention are the VB.Net equivalents); sadly, I have no experience with using DirectX so this is beyond me without some significant research. However, I did find another example of video capture for VB6 here (https://www.codeproject.com/articles/13389/accessing-webcam-in-visual-basic) which, roughly converted, looks like this: Global Const wm_cap_driver_connect = WM_USER + 10 Global Const wm_cap_set_preview = WM_USER + 50 Global Const WM_CAP_SET_PREVIEWRATE = WM_USER + 52 Global Const WM_CAP_DRIVER_DISCONNECT As Long = WM_USER + 11 Public Const WM_CAP_DLG_VIDEOFORMAT As Long = WM_USER + 41 Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Declare Function capCreateCaptureWindow Lib "avicap32.dll" Alias "capCreateCaptureWindowA" (ByVal a As String, ByVal b As Long, ByVal c As Integer, ByVal d As Integer, ByVal e As Integer, ByVal f As Integer, ByVal g As Long, ByVal h As Integer) As Long
Dim hwdc As Long Dim startcap As Boolean
Form form1 = "", 4, 23, 353, 316 + Screen.cyCaption Ocx Command cmdVideoFormat = "Video Format", 223, 260, 81, 33 Ocx Command cmdClose = "Close", 127, 260, 81, 33 Ocx Command cmdcapture = "Capture", 31, 260, 81, 33 Ocx Image picture1 = "", 8, 8, 320, 240 : .BorderStyle = 1
Do : Sleep : Until form1 Is Nothing
Sub cmdcapture_Click() Dim temp As Long hwdc = capCreateCaptureWindow("Capture Window", WS_CHILD Or WS_VISIBLE, 0, 0, 320, 240, picture1.hWnd, 0) If (hwdc <> 0) Then temp = SendMessage(hwdc, wm_cap_driver_connect, 0, 0) temp = SendMessage(hwdc, wm_cap_set_preview, 1, 0) temp = SendMessage(hwdc, WM_CAP_SET_PREVIEWRATE, 30, 0) startcap = True Else MsgBox ("No Webcam found") End If End Sub
Sub cmdClose_Click() Dim temp As Long If startcap = True Then temp = SendMessage(hwdc, WM_CAP_DRIVER_DISCONNECT, 0, 0) startcap = False End If form1.Close End Sub
Sub cmdVideoFormat_Click() Dim temp As Long If startcap = True Then temp = SendMessage(hwdc, WM_CAP_DLG_VIDEOFORMAT, 0, 0) End If End SubIf you need to expand functionality further, see msdn.microsoft.com/en-us/library/windows/desktop/dd757696(v=vs.85).aspx. I hope this is helpful.
|
|
|
Post by ventilo25 on Sept 11, 2017 15:22:56 GMT 1
Thank you very much DragonJim for your answer and for the example that you propose. I know the functions of Avicap.dll that I already used, but unfortunately they no longer work under Win64! That's why I'm looking for an equivalent with DirectShow ... Sincerely
|
|
|
Post by dragonjim on Sept 11, 2017 15:32:54 GMT 1
Hi,
Sorry my post wasn't much help.
I do not have a webcam on the computer I am currently using (I am thus unable to test the program I sent you with a video feed) but it is Win10 Pro 64bit and it did not throw an error. Is the error that the API no longer works? If so, I wonder if the Unicode version of the API would work instead?
|
|
|
Post by ventilo25 on Sept 11, 2017 16:26:21 GMT 1
Hi, yes the code works under Win 10/64 bits without error but the video capture is black!
|
|
|
Post by ventilo25 on Sept 11, 2017 19:33:06 GMT 1
I tried with capCreateCaptureWindowW (Unicode) instead of capCreateCaptureWindowA (ANSI), it still does not work ... But i don't no if i have the Unicode version of the API... Thank you for the help !
|
|
|
Post by dragonjim on Sept 11, 2017 22:42:13 GMT 1
Hi,
If you have capCreateCaptureWindowA, then you should have capCreateCaptureWindowW as they should both be in the avicap32.dll. I tried it on my dummy operation this end and it didn't throw an error, so it probably is not working in the same way that capCreateCaptureWindowA isn't.
Looking at this page (https://social.msdn.microsoft.com/Forums/vstudio/en-US/f7dacb67-485b-4bb7-b2ff-76c48adce0d6/webcam-vfwh-problem-black-screen?forum=vcgeneral), some people having the same problem came to the conclusion the problem was the YUY2 colour format and fixed it by calling the Video Format Dialog; the third command button on the example I posted is supposed to do just that: does it work (i.e. does it call the Video Format dialog box)?
If not, try changing the message constant to WM_CAP_DLG_VIDEOSOURCE (= WM_USER + 42) which should show a dialog for the video source (the wparam and lparam values are both zero).
Finally, partway through that chat, some suggested changing the preview rate to 66 - it is set at 30 in my example - does that make a difference?
Fingers crossed one of these works...
|
|
|
Post by ventilo25 on Sept 12, 2017 9:28:14 GMT 1
Hi,
the problem is solved, works perfectly under the last one version of Windows 10 under 64bits processor!
You were right, the black screen problem came from the camera setting, Format, Stream Settings, Pixel Space (Bit), and Compression: that I changed (there were 3 options in the combo box)and the image is re-emerged. By returning a second time to this setting, that there are no more options available (nothing in the combo box).
The video capture even works in high definition (1024x576) or more!
Obviously it's always the functions of Avicap32.dll and no DirectShow! Thank you for your help, Amicalement!
|
|
|
Post by dragonjim on Sept 12, 2017 11:40:53 GMT 1
Hi,
I'm glad to hear that everything is now working - and now in HD!
Just as a postscript (FWIW): according to the documentation, the Video Format dialog box is derived from the camera's drivers rather than being an internal Windows object, and there is always a chance that cheap cameras may not support such a box, which is why it is worth trying the WM_CAP_DLG_VIDEOSOURCE option as well - it should have one or the other.
|
|