I recently studied audio and video processing programming. The first problem I encountered was that the capDriverConnect function always fails to capture the video source. A capture source dialog box is displayed, after I click "OK", the return value of the function is 0, and the capture fails. I also searched the internet for this information and found that many people encountered this problem, we all said that it would take many connections to succeed. The number of connections is uncertain. It is just luck. If you are lucky, you can connect them. However, no solution is provided, after many experiments, I found a solution to this problem.
I checked the books on VC ++ video processing, and the connection code provided in it is all in the following form:
If (capDriverConnect (m_hwnd, 0) = TRUE)
{
...... // Indicates that the connection is successful and other code can be executed.
}
Else
{
MessageBox ("connection failed ");
Return false;
}
In this case, I found that the same problem we encountered was that we could not connect to the video driver. Later I thought that since multiple connections may be able to be connected, I would like to put it in the While loop to see how the situation works.
I changed the program.
While (capDriverConnect (m_hwnd, 0 )! = TRUE)
Continue;
I found that only one capture source dialog box is displayed, and you can connect to it after clicking OK. So if anyone encounters this problem, we suggest you replace if with While
The specific reason is unknown.