Page 1 of 4 1234 LastLast
Results 1 to 40 of 125

Thread: VB6 - DirectShow WebCam Minimal Code

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    VB6 - DirectShow WebCam Minimal Code

    There are a number of possible APIs in Windows for previewing and capturing from webcams. One of the most popular for its broad support on Windows versions and its relative ease of use when requirements are simple is the AviCap/Video for Windows API.

    But a downside of VfW is that the driver model Windows uses to support video capture devices changed after the end of 16-bit Windows (Win3.1, etc.). This means several things, but most commonly frustrating is that instead of mapping multiple webcams as device 1, 2, ... 9 they work through a compatibility layer thats maps one of them as device 1.

    This can make selecting the webcam to use difficult to impractical. And using more than one webcam at a time doesn't seem possible.

    The usual answer has been: "Use DirectShow instead of VfW."


    DirectShow vs. VB6

    One problem with using DirectShow is that Microsoft seemed to have lost enthusiasm after providing only a partial implementation. The parts of DirectShow (also called ActiveMovie) we did get a VB6-friendly API for are implemented in the Quartz.dll which should be part of Windows in any recent version (and perhaps even back to most "late" Windows 95 versions like 95B or OSR2.x).

    You can still do a lot of things using just what we have, but the finer points of using DirectShow in VB6 require a 3rd party DLL to wrap a few more DirectShow C++ interfaces.


    This "Minimal Approach" to VB6, DirectShow, and WebCams

    What I have done here is to try to stretch things as far as I could manage.

    Here is what you can do:

    • Choose among your webcams and display a live preview image.
    • "Snap" and display a still image from the webcam feed.


    Here is what you can't do:

    • Get a "friendly" list of just the usable webcams.
    • Control the capture resolution/dimensions or other capture settings or even raise the built-in dialogs to let the user do so.



    The Demo

    What I wanted to accomplish was to see how far I could get with the two tasks we can perform without using any 3rd party libraries.


    Form1

    This is the main UI Form, which uses Form2 as a dialog when requested via its menu ("Add new camera...").

    There is a lot more code there than I'd like that does nothing except manage the menu. As you add cameras they are added to the menu. There is also code there to load and save "settings" which include the index of the selected camera and list of added cameras by name.

    Basically a lot of UI-management code which I hope doesn't obscure the DirectShow-related logic itself.

    The other ugly hunk of code in there is the BuildGraph() function, which is a small interpreter of a sort that processes a "filter script" and a "connection script" to add the necessary filters and connect them to create a webcam preview graph for DirectShow.


    Form2

    Since I can't find any way to find just the list of usuable webcams, the user has to pick them out from among the full list of available "filters" (as they are called)! Not practical at all for a real application, but it works for a test/demo program.

    That's what Form2 in the demo Project is for, a dialog from which to pick new cameras.

    Note that your camera might appear there once, twice, or even three or more times depending on how many "filters" of different kinds it supports. Just pick any of them, the demo program will just use the name and sort it out later.


    Module1

    This contains some GDI and OLE API calls to convert the captured frame from a "packed DIB" into a StdPicture object that can be used with PaintPicture, etc. This raw StdPicture is created using a "memory DC" so there are some limits on how you can use it, i.e. simply assigning it to a PictureBox.Picture has some issues.

    But in this demo we need to scale it anyway since we can't control the actual capture dimensions.

    You could rework this passing in the hDC of a Form, PictureBox etc. I suppose.


    Running the DSMini1 Project

    The attached ZIP archive contains the entire Project.

    All you should need to do is unzip the archive, then open the Project in VB6. If you have a webcam connected, you can just go ahead and run it within the IDE.

    From there you will have to "Add" your webcam by browsing the filter list.

    After a valid add, the live preview starts immediately at the left.

    Clicking on the Snap button should take a snapshot and display it in the PictureBox at the right.

    If you have another webcam connectd you shuld be able to add that one too. Once you have two or more added you can choose among them via Form1's menu.

    Settings are persisted in Settings.txt, so a subsequent run should save you the trouble of picking cameras again.


    Remarks

    I don't know what webcams this will work with, but I know it works with two very different ones I've tried so far.
    Attached Images Attached Images   
    Attached Files Attached Files
    Last edited by dilettante; Jan 30th, 2013 at 04:05 AM. Reason: updated attachment, corrected small non-fatal bug

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    To show that you can use these techniques to run multiple webcams, I give you DSMini2.

    The menus are rearranged, the settings file contents are slightly different, and the snapshot function has been pulled out, but now if you have multiple webcams you can preview two at once. Pretty much all of the other comments about running DSMini1 apply to DSMini2.


    One thing not mentioned about DSMini1 is that it scales the views to fit the camera's aspect ratio. The same applies in DSMini2, but it might be more noticeable if your webcams have different aspect ratio settings: one view will be "shorter" than the other one.
    Attached Files Attached Files
    Last edited by dilettante; Jan 30th, 2013 at 04:17 AM.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    A little refinement. Mainly small bug fixes in Form menu handling, a tweak to the logic for creating a StdPicture snapshot, etc.

    Big change: Replaced a bunch of inline DirectShow related code in Form1.frm by a new DSPreview.ctl UserControl.


    DSMini3 is the improved version of the single cam/snapshot demo (DSMini1).

    DSMini4 is the improved version of the dual-cam demo (DSMini2).
    Attached Files Attached Files

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Hmm, DSMini3 has a small flaw.

    When you select a camera to preview that has a different aspect ratio from the default one it expects, it fails to adjust the "snapshot" PictureBox. The result is some stretching or squishing of the snapshot.

    Not a big deal but something to consider. If you need to deal with it I'm sure you can on your own. Not worth reposting an update I suppose. DSMini1 was handling this issue properly though.
    Last edited by dilettante; Jan 31st, 2013 at 01:15 PM. Reason: just a typo

  5. #5
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: VB6 - DirectShow WebCam Minimal Code

    I don't have a webcam attached to my PC but, nonetheless, I lifted some of your code into a VB6 project of my own as I was interested in your GetCurrentImage implementation. It does indeed work very well but is, however, a lot (noticably!) slower than using the SampleGrabber approach.

    Is this because of your over-generosity of the buffer size or is it just intrinsically slower?
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  6. #6
    Addicted Member
    Join Date
    Jan 2013
    Posts
    148

    Re: VB6 - DirectShow WebCam Minimal Code

    yes I have checked it but i only give me black picturebox, no image at all, only black. that is why I wonder why that ocx is having no problem except that it has no save to file or to db capability.

    attach is the screenshot of the result
    Attached Images Attached Images  
    Last edited by ravemaster; Feb 1st, 2013 at 01:20 PM.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by ColinE66 View Post
    I don't have a webcam attached to my PC but, nonetheless, I lifted some of your code into a VB6 project of my own as I was interested in your GetCurrentImage implementation. It does indeed work very well but is, however, a lot (noticably!) slower than using the SampleGrabber approach.

    Is this because of your over-generosity of the buffer size or is it just intrinsically slower?
    SampleGrabber works without pausing the filter graph, but GetCurrentImage requires that. However I don't know of any way to use SampleGrabber in a VB6 program without additional helper DLLs, so GetCurrentImage is useful in "first steps" examples of working DirectShow programs.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by ravemaster View Post
    yes I have checked it but i only give me black picturebox, no image at all, only black.
    Could be lots of things. Might be that your webcam has default settings leading to a black picture. Or it might be that the filter graph I am building doesn't work with your camera. This is where you would need to experiement since there may not be a universal solution.

    Start by working with the graphedt.exe utility from the DirectShow (now part of the Windows) SDK.

    What camera do you have?

    Quote Originally Posted by ravemaster View Post
    that is why I wonder why that ocx is having no problem except that it has no save to file or to db capability.
    Ocx? What ocx?

    Save to file or DB? This is a code sample. If you want a full blown program for some purpose you can add more code or hire a programmer. This is CodeBank, not UtilityBank.

    Plus at this point saving the image isn't too useful. First you need control over the capture format or risk getting nothing but tiny low-res images. This kind of control also requires a 3rd party helper DLL.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Ok, here is a more elaborate example DSElaborate5, based on DSMini1 & DSMini3 (one camera, with snapshot capture).


    Background Info

    I have not found a way to get these features without a helper DLL that can wrap a few more DirectShow interfaces in "Automation" (ActiveX) form.

    I decided to use what appears to be the widely used FSFWrap.dll from Geraint Davies Consulting Ltd. (GDCL). I says appears to be widely used, because oddly enough some heavy searching of the Web didn't turn up a single useful example of the use of this library. All I found was an example from GDCL that doesn't seems to work with cam-capture, and somebody's attempt to convert that same VB6 example to VB.Net 2XXX (not sure which VB.Net, don't care).

    My conclusion:

    This was never that popular, or it used to be and a lot of posted examples have disappeared since 2005 or so, or it is quite popular but most users are too lazy or greedy to share by posting helpful information and working code...

    ... or I'm just not that great at searching.


    This New Example

    In order to run this example yourself you will have to obtain and install this library. I'm attaching the instructions along with a .DEP file that the author failed to provide for the library. I can't provide the DLL, because (a.) we aren't supposed to attach binaries and (b.) it isn't mine to hand out.

    So here are the new features:

    • Camera selection dialog is now built selectively, i.e. it should list your cameras and only your cameras.
    • Capture (pin) properties can be viewed and altered when a camera is started.
    • Camera (filter) properties can be viewed and altered once a camera has been started, and these changes are "live."

    I can't find a way to make the pin properties pages work properly except as part of building the filter graph and starting it. Perhaps somebody else has an alternative that allows changes to these while the graph is running.


    Since I now have a way to configure the pin properties (mainly the capture dimensions) I have added an unrelated feature:

    • Both Snap and Snap+Save (to JPEG file) buttons are present.

    And "Snap to Byte array" could be added. The code is there, you just need Edanmo's olelib.tlb for that. See the new GPP2J.cls module's header comments for details.


    I hope you find this new version interesting, if not useful.



    mod comment - Link to FSFWrap removed as it's closed source. Its easy enough to google for though.
    Attached Files Attached Files
    Last edited by FunkyDexter; Jun 30th, 2016 at 08:02 AM. Reason: new attachment, menus were a mess in 5 - try 5a

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by dilettante View Post
    SampleGrabber works without pausing the filter graph, but GetCurrentImage requires that. However I don't know of any way to use SampleGrabber in a VB6 program without additional helper DLLs, so GetCurrentImage is useful in "first steps" examples of working DirectShow programs.
    Ok, so that's what the docs say.

    But I found somebody skipping the pause yet doing GetCurrentImage() calls... so I tried it and things are working just fine!
    Attached Files Attached Files

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Ok, one more time...

    This version is the same as 5b above, but with a change to the filter graph and method by which the graph is connected. All told just a few lines difference.

    It might address the "black picture" problem though.


    ffdshow

    It is also worth noting that if you have ffdshow installed, a dialog from it may appear when testing in the IDE and again for the compiled EXE. It seems to maintain a "blacklist" or something though, so you can choose "don't show this again for this program" and you won't be bothered again.

    Of course you'll get that both for VB6.EXE (runs in the IDE) and the compiled program, separately. And you can always opt to be reminded each time instead if this matters to you.
    Attached Files Attached Files

  12. #12
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: VB6 - DirectShow WebCam Minimal Code

    I actually use capstill.dll in my program (link in sig) and I do recall seeing some code at his site for working with webcams but, if memory serves, it accompanied his fsfwrap.dll - you might want to take a look at that.

    EDIT; sorry for confusion if you happened to read the pre-edit version of my post; capstill.dll is the one that facilitates the SampleGrabber, not fsfwrap.dll. Within one of the demo projects (can't remember if it was capstill or fsfwrap) I recall seeing some code related to webcams.
    Last edited by ColinE66; Feb 2nd, 2013 at 12:29 PM.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    I still have to get around to looking at the Sample Grabber. I see that it is a deprecated filter with Merit set to MERIT_DO_NOT_USE, but what isn't deprecated by Microsoft these days?


    The point of this thread was to try to demystify the use of DirectShow webcam capture in VB6. I'm not sure that this can be done once you start requiring extra helper DLLs.

    My examples 3 and 4 above are refinements of 1 and 2 and don't introduce anything complex. They also get results as good or better than what most people are doing with the older VfW API anyway.

    What 1 through 4 lack is the ability to set the most minimal capture params, such as the capture image size. While my several stabs at example 5 address this, it is indirect (i.e. via the properties dialogs).


    So all I really care about beyond this is setting those within the program itself, in code instead of through dialogs. Well, that and trying to figure out where the "black picture" problem comes from for some cameras or users and fixing that if possible.

  14. #14
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: VB6 - DirectShow WebCam Minimal Code

    OK. I was just trying to help as earlier you said this:

    Quote Originally Posted by dilettante View Post

    I decided to use what appears to be the widely used FSFWrap.dll from Geraint Davies Consulting Ltd. (GDCL). I says appears to be widely used, because oddly enough some heavy searching of the Web didn't turn up a single useful example of the use of this library. All I found was an example from GDCL that doesn't seems to work with cam-capture, and somebody's attempt to convert that same VB6 example to VB.Net 2XXX (not sure which VB.Net, don't care).

    My conclusion:

    This was never that popular, or it used to be and a lot of posted examples have disappeared since 2005 or so, or it is quite popular but most users are too lazy or greedy to share by posting helpful information and working code...

    ... or I'm just not that great at searching.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Thanks, I missed your link. I normally have signatures turned off since so many are huge blobs of images and other distractions.

  16. #16

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    I tried 5b with a laptop having a camera identifying itself as Chicony USB 2.0 Camera and it works there too.

    One quirk I did see was that if I changed the capture dimensions from those it defaults to (which are never the dimensions marked "(default)" in the properties dialog???)... the image can come up very dark.

    But with this dark image, if I then choose the Configure camera properties... dialog and once that pops up I click on the Default button there... the camera seems to automatically adjust the exposure to something usable.

    I'm not saying this is the root of the "black picture" issue, but it did seem odd.

  17. #17
    New Member
    Join Date
    Feb 2013
    Posts
    9

    Re: VB6 - DirectShow WebCam Minimal Code

    hi
    first thank you a lot for the app it helped me a lot
    i added it to my project
    i still new to programming i have 5 month now
    my only problem is :
    is there a way to filter the list items to show only the camera drivers because there is a lot drivers shown
    thanks for help

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    To limit the list of filters to capture filters (cameras) you need to use a 3rd party helper library. That is because the necessary interfaces to do this in VB6 were not provided by Microsoft.

    See post #9 and later for examples of this, using the popular helper library FSFWrap (free). Those are the "Elaborate" examples: 5a, 5b, and 5c.

  19. #19
    New Member
    Join Date
    Feb 2013
    Posts
    9

    Re: VB6 - DirectShow WebCam Minimal Code

    hi Mr delettante :
    thank you a lot for the help
    i did it it works great thanks a lot so much

  20. #20
    New Member
    Join Date
    Feb 2013
    Posts
    9

    Re: VB6 - DirectShow WebCam Minimal Code

    hi delettante
    i need an advice from you if possible
    how i can learn how to use any library file
    for example i want to learn how to use twain32.dll or FSFwrap.dll
    or any other dll file what is the best way thanks

  21. #21

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    You need to get the DLL's documentation.

    For FSFWrap there isn't much that I can find except what its author posted years ago. So to use it you have the few hints there, his sample programs there, what you can work out using the Object Browser in the VB6 IDE, and what you can guess based on the C++ interfaces documented in the MSDN Library.

    As far as I can tell not many people ever did much with FSFWrap, or if they did they never wrote much about it that I could find on the Web.

    Documentation can be as hard to create (or harder) than writing the code itself. So many free libraries don't have much.

    The TWAIN API is very old (though still popular). But because it is old it can be very hard to find any Microsoft documentation for it now, plus it is "owned" by http://www.twain.org/ so you might try there.

  22. #22
    New Member
    Join Date
    Feb 2013
    Posts
    9

    Re: VB6 - DirectShow WebCam Minimal Code

    hi
    so to learn how to use any library i have to get its documentation because its always seems for me that the codes is hard to learn and understand
    thank you for your advice
    thanks a lot

  23. #23
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: VB6 - DirectShow WebCam Minimal Code

    xxxxxxxxxxxxxxxxxxxxxxxxxxx
    Last edited by ladoo; Mar 4th, 2013 at 08:24 PM.

  24. #24

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    What you have posted is an example of using AviCap in the most simplistic fashion possible.

    I see you have edited this out of post #23 now.

    This is extremely common and there are quite a few CodeBank examples already posted. Your program also makes use of the clipboard in way that programs never should when at all possible. There are far better AviCap examples here in the CodeBank that do not destroy the user's clipboard data.

    And your attachment has nothing to do with using DirectShow from VB, which is what this thread is all about.


    The reason to try to use DirectShow instead of AviCap is that it offers your program much more control over capture formats and camera settings, allows selection among multiple cameras, capture from more than one camera at a time, and offers other potential advantages.

    That's why this thread is here: to help people start programming using DirectShow instead of the old AviCap API.
    Last edited by dilettante; Mar 11th, 2013 at 06:12 PM.

  25. #25
    Banned
    Join Date
    Nov 2012
    Posts
    1,171

    Re: VB6 - DirectShow WebCam Minimal Code

    system is overheating...............................................cool down

  26. #26
    New Member
    Join Date
    Mar 2013
    Posts
    1

    Re: VB6 - DirectShow WebCam Minimal Code

    Hello,

    First, thanks for this thread.

    I tried 5C but no luck, I keep getting 'BlueGraph error' , tried with several webcams. (Win8 x64 btw)

  27. #27
    New Member
    Join Date
    Mar 2013
    Posts
    2

    Works with USB web cam, but not USB Video (Video to USB adapter)

    downloaded the DSMini4.zip and find it works great with a USB cam, but not with a video to USB adapter.
    In this event, the EasyCap adapter. It sees the cam as 'SMI grabber device' (which works as I can see the pic in other apps), but when I try preview I get-
    ----------------------------------
    Selected camera for preview 0 failed, may not be connected
    SMI grabber device
    BuildGraph error 1
    ----------------------------------

    Any suggestions?

  28. #28

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by SpaceDonkey View Post
    I tried 5C but no luck, I keep getting 'BlueGraph error' , tried with several webcams. (Win8 x64 btw)
    Quote Originally Posted by Mike Scott View Post
    downloaded the DSMini4.zip and find it works great with a USB cam, but not with a video to USB adapter. In this event, the EasyCap adapter.

    Any suggestions?
    I don't have a Win8 test system set up but I would expect it to work there with no problems.

    However these programs are only able to handle some generic cases so finding webcams that won't work is very likely. These sample programs are probably best treated as examples of how you can use DirectShow in VB6 programs.

    DirectShow covers a large set of multimedia operations through "building blocks" and your programs need to "assemble" several blocks together to "spell a word" (to stretch an alphabet-block analogy). These programs are making assumptions about the "block" at the beginning and the "block" at the end and try to assemble the necessary "blocks" to span the gap between them.

    It is a little more complicated even than that makes it sound. Every "block" can have zero to many inputs and zero to many outputs, and your program needs to string the blocks together by joining the right outputs to the right inputs.

    Your capture device (camera) may not have the particular output "pin" as they're called that my programs here expect. Or it might have the right output pin, but it may require another intermediate filter block to transform its output data stream.


    To handle things truly generically (to write a "universal" program) you'll probably need to understand the process better than I do, you'll need more complicated code, and it may not even be possible in VB6 since only a few items are made available in a form easily used in VB6. The FSFShow wrapper helps, but may not make enough of DirectShow available to do the entire job.


    If you have the Windows SDK you'll find that the old DirectShow SDK has been merged into it. This gives you a tool to play with called graphedt.exe ("GraphEdit"):

    Name:  sshot.png
Views: 36071
Size:  43.3 KB

    This might give you something to experiment with so you can improve what I have tried to do in these sample programs.

    Of course translating from there to a VB6 program can be tricky, and it will require that you study the DirectShow documentation in some detail. But perhaps my sample programs and the FSFWrap author's samples will help get you there.

  29. #29
    New Member
    Join Date
    Mar 2013
    Posts
    2

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by dilettante View Post
    I don't have a Win8 test system set up but I would expect it to work there with no problems.

    However these programs are only able to handle some generic cases so finding webcams that won't work is very likely. These sample programs are probably best treated as examples of how you can use DirectShow in VB6 programs.

    DirectShow covers a large set of multimedia operations through "building blocks" and your programs need to "assemble" several blocks together to "spell a word" (to stretch an alphabet-block analogy). These programs are making assumptions about the "block" at the beginning and the "block" at the end and try to assemble the necessary "blocks" to span the gap between them.

    It is a little more complicated even than that makes it sound. Every "block" can have zero to many inputs and zero to many outputs, and your program needs to string the blocks together by joining the right outputs to the right inputs.

    Your capture device (camera) may not have the particular output "pin" as they're called that my programs here expect. Or it might have the right output pin, but it may require another intermediate filter block to transform its output data stream.


    To handle things truly generically (to write a "universal" program) you'll probably need to understand the process better than I do, you'll need more complicated code, and it may not even be possible in VB6 since only a few items are made available in a form easily used in VB6. The FSFShow wrapper helps, but may not make enough of DirectShow available to do the entire job.


    If you have the Windows SDK you'll find that the old DirectShow SDK has been merged into it. This gives you a tool to play with called graphedt.exe ("GraphEdit"):

    Name:  sshot.png
Views: 36071
Size:  43.3 KB

    This might give you something to experiment with so you can improve what I have tried to do in these sample programs.

    Of course translating from there to a VB6 program can be tricky, and it will require that you study the DirectShow documentation in some detail. But perhaps my sample programs and the FSFWrap author's samples will help get you there.
    Unfortunately, the SDK kit looks like it's for Win8 only. I'm on XP :-(

  30. #30

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by Mike Scott View Post
    Unfortunately, the SDK kit looks like it's for Win8 only. I'm on XP :-(
    When you snooze you lose I guess. XP is dead and cold now with Vista on the chopping block next.

    There should still be a Windows 7 SDK for a few months.

    And you can still order old SDK CDs for a shipping fee from SDKs.


    But as far as I know even the Win8 SDK download should install fine on an XP system. Just note that a lot of old stuff is gone and some of the new stuff won't run on XP.


    Also note that your old MSDN Library CDs that VB6 uses for it online Help contain most of the C++ and VB6 DirectShow documentation that exists. The October 2001 issue is best, but any from shortly before then should be Ok too.
    Last edited by dilettante; Mar 11th, 2013 at 11:30 PM.

  31. #31
    New Member
    Join Date
    Jul 2013
    Posts
    8

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by dilettante View Post
    However these programs are only able to handle some generic cases so finding webcams that won't work is very likely. These sample programs are probably best treated as examples of how you can use DirectShow in VB6 programs.

    DirectShow covers a large set of multimedia operations through "building blocks" and your programs need to "assemble" several blocks together to "spell a word" (to stretch an alphabet-block analogy). These programs are making assumptions about the "block" at the beginning and the "block" at the end and try to assemble the necessary "blocks" to span the gap between them.
    hello Dilletante!

    This is Red from the Philippines.

    I've tried your webcam demo number 2(DSMini2) and it worked for me.

    However, when i tried doing some video saving stuff, it caused me several sleepless nights because
    i can't seem to get it working. in fact, i don't know how to start. I Googled sample codes BUT it gave me
    lots of C/C++/C# codes instead of VB6. The closest VB6 code that i tested are your sample codes posted here.

    Some say that VB6 can't do deep webcam programming, instead they recommend C/C++/C#..
    BUT i don't believe it. I've seen how you code and i know that you do webcam recording. You have done
    capturing "pins" in your codes "but the saving to file" part is not included..

    I know there are others out there that use classic VB6 BUT don't have webcam video recording in their programs.
    Since you are an expert in this field, please share us a sample code on how to record the "capture pin" while the
    "preview pin" is displaying the video. Another minimal code will do.

    see attached images:
    Name:  pins_code.JPG
Views: 34120
Size:  213.0 KBName:  actual_screenshot.JPG
Views: 37262
Size:  40.7 KBName:  DirectShow Document 1.JPG
Views: 33860
Size:  183.9 KBName:  DirectShow Document 2.JPG
Views: 33696
Size:  122.8 KB

  32. #32

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Sorry Red,

    I'm no expert, I was only playing with it a bit to see how far I could get without using helper libraries. Then I looked around and found one simple helper library and played with that a little.

    It looks like you have dug a little deeper. Maybe you can get AVI writing working and post sample code for us to look at here.

  33. #33
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: VB6 - DirectShow WebCam Minimal Code

    There's a File Writer filter that comes with windows that can be added to the graph. I've never used it myself but have a Google....
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  34. #34
    New Member
    Join Date
    Jul 2013
    Posts
    8

    Re: VB6 - DirectShow WebCam Minimal Code

    Big thanks to your reply Dilettante..
    sorry, mispelled your name from my previous post

    i'll dig some AVI stuff then post the codes here when i'm done.
    Again, the codes you posted are very helpful to non-experts like me (i consider you as an expert).

    BTW, i tried FFMPEG to record webcam's video.
    It did work but you need to "STOP" the graph from VB6 ==> fgmVidCap(0).STOP

    From what i saw, there should ONLY BE 1 INSTANCE of an "OPEN webcam"
    before it pushes with the recording.
    Meaning, if you want to use FFMPEG to record a webcam's video, STEP 1 is to "close that particular webcam".
    STEP 2 is the the FFMPEG execution.

    Here's how i did the recording:
    ffmpeg -t 00:00:30 -f dshow -i video="USB Video Device" -r 30 -s 480x320 -y sample_1.AVI


    -t 00:00:30 time to record is 30 seconds
    -f dshow it uses DirectShow? i'm not sure
    -i video="USB Video Device" video input comes from my cheap USB Webcam
    -r 30 rate is 30 frames per second
    -s 480x320 video size
    -y sample_1.AVI output name, -y means overwrite if file exists


    Dilettante, i need to continue previewing my webcam WHILE the FFMPEG code is executed.
    Any suggestion?

    Thank you.

  35. #35
    New Member
    Join Date
    Jul 2013
    Posts
    8

    Re: VB6 - DirectShow WebCam Minimal Code

    Thanks for your reply ColinE66!

    yes, sure i will Google what you said.
    Hope i can find it.

  36. #36

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by redp View Post
    Dilettante, i need to continue previewing my webcam WHILE the FFMPEG code is executed.
    Any suggestion?
    There may be DirectShow filters that can split the data into two paths (sort of a "Y adapter").

  37. #37
    New Member
    Join Date
    Jul 2013
    Posts
    8

    Re: VB6 - DirectShow WebCam Minimal Code

    Yes Dilettante, i agree with you... That "data(video) splitter" exists somewhere. Many have done it using C/C++/.Net..

    For now, I still want to do it with classic VB6.. Gut feel tells me that it can be done.

    Anyway, when i'm done with this splitter thing, i will come back here and thank you again

    - Red

  38. #38
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 - DirectShow WebCam Minimal Code

    There's two default-splitters in the DirectShow-Filterlist:
    - one is the "Smart Tee"
    - and the other one is the "Infinite Pin Tee Filter"

    the Smart-Tee is suitable in Video-scenarios, whenever a given capture-device does not already offer two separate Capture- and Preview-Pins.
    Internally the splitting is ensured - but with a preference of the stream which goes out on the Capture-Pin - that ensures a better behaviour with regards to dropped frames -
    and that capture-pin is usually, where Video-encoders and another standard-filter, the "Avi Writer Filter" usually make one "downstream-path", whereas the Preview-Pin
    leads into the usual "Video Renderer"-Filter as the other endpoint.

    The "Infinite Pin Tee Filter" does not prefer one splitted stream over the other - it tries to provide the same stream-samples across all branches - it is the more generic one.

    Below is a ScreenShot of my updated NewGraphBuilder-example, showing the "Smart-Tee in action"
    The NewGraphBuilder-App (with the additional help of three typelibs) is now covering nearly all the functionality
    of the original Builder-example which came with the FSFWrap.dll-Helper-lib.

    I've also cleaned up the code of the original Builder-Example, which is now reduced to about half the lines it formerly had.

    The used Typelibs are:
    - ActiveMovie Control Typelib (that's the usual one, which is always useful in VB6/DirectShow-contexts)
    - MS Video Control 1.0 Typelib (this was offering such nice interfaces as IBaseFilter, IGraphBuilder etc. - so no need to define them in ones own typelib)
    - Edanmo's OleInterfaces and functions (for more generic OLE-interactions per IIDs - but also has IPersistStream- and other interfaces, allowing for *.grf loading/saving)

    In the Zip-Archive I've included Eduardo Morcillos olelib.tlb (later on there's no need to include it into your setups) - and the other two are system-standard-libs.
    Attached Images Attached Images  
    Attached Files Attached Files

  39. #39
    New Member
    Join Date
    Jul 2013
    Posts
    8

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by Schmidt View Post
    Below is a ScreenShot of my updated NewGraphBuilder-example, showing the "Smart-Tee in action"
    The NewGraphBuilder-App (with the additional help of three typelibs) is now covering nearly all the functionality
    of the original Builder-example which came with the FSFWrap.dll-Helper-lib.
    Schmidt, glad to hear from another expert(you are truly a master in this regard)..

    I will try the attached code then come back.
    And to Dilettante/ColinE66, finally Schmidt's code is the answer to the "splitter" problem..

    Though I haven't tested it, i'm thanking you Schmidt for this contribution in behalf of those users who prefer classic VB6.
    This is a huge help from non-experts like us.

  40. #40
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 - DirectShow WebCam Minimal Code

    No need for "praise in bold letters" (makes not only me feeling a bit uncomfortable I'd guess) ...

    Your: "I will try the attached code then come back" - is already enough. :-)

    As for playing around with the Builder-App ...
    Anything you are able to "click together" (Graph-wise, with your Mouse), you should be
    able to accomplish (finally, in your own Application) also per direct code.

    If you were able to construct a certain, well-working graph (and know all the filter-members
    who make up this graph) - then try to achieve the construction in as few "Click-steps" as possible.

    Especially the [Connect Downstream...] button (with its CurrentPin.Render-call behind it)
    can be a big help in attempts on "cutting down the amount of actions until a certain graph is running".

    Also "inverse graph-construction" would be possible this way - e.g. when you use the
    [Connect Downstream...]-Button to automatically construct larger parts up to their endpoints -
    and then if the result is not satisfying, but only in a few "last parts" -> just step-backwards,
    removing Filters on the graph - and then construct only what you deleted anew (with better
    suiting filters, to reach your endpoints).

    There's still a lot one could do with regards to "easing graph-construction even more for VB-Classic" -
    but that would require (if done correctly) a special wrapping of all the important classes who take part
    in such DirectShow-scenarios:
    cGraph
    cFilter
    cPin

    'more comfortable Source-classes
    cVideoInput
    cAudioInput
    cFileInput

    'comfortable to use Classes "in-between"
    cSplitter
    cMuxer
    cEncoder
    cDecoder
    cSampleGrabber

    'more comfortable to use EndPoint-Classes
    cVideoEndpoint
    cAudioEndpoint
    cFileEndpoint


    That's not all that much - but each of those Objects could (and should) offer nice Properties, nice
    VB-friendly Enumerators (wrapped in VB-Collections) - and much better Find- and "Plug-together"-
    comfort-functions ... best done in a way, so that all the used Typelibs and Interfaces remain
    hidden (in case those new Classes are wrapped in a ActiveX-Dll-Project) - so that the end-user
    of this DShow-wrapper-Dll would need only to check-in this single reference into his DirectShow
    related projects (the references to quartz.dll, msvidctl.dll and olelib.tlb could remain hidden in the Dll-Project).

    But maybe we should discuss this not in this thread, but start a new Thread for that here in the
    code-bank. I'd be willing to do some ground-work and post Implementations for some of the
    BaseClasses as: cGraph, cFilter, cPin and e.g. cVideoEndpoint and maybe also cSampleGrabber -
    it would be up to the community, to fill in the blanks (the remaining comfort-classes + functionality
    within those classes).
    Especially when dilettante would join in, such an encapsulation could evolve nicely I'd think.

    Olaf

Page 1 of 4 1234 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width