Page 2 of 4 FirstFirst 1234 LastLast
Results 41 to 80 of 125

Thread: VB6 - DirectShow WebCam Minimal Code

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

    Re: VB6 - DirectShow WebCam Minimal Code

    I'd be happy to contribute to such an effort and have more experience than most with regard to graph-building in VB6. In particular, I am very interested in a robust SampleGrabber. Geraint Davies capstill.dll is fine up to a point, but will only accept 24bit RGB inputs and some upstream filters are not always willing to provide this! An overlay filter would be great too as would (getting greedy now!) a filter that one could use to adjust RGB, HSL on-the-fly.
    If you don't know where you're going, any road will take you there...

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

  2. #42
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 - DirectShow WebCam Minimal Code

    Ahh, Colin ... since we know each other for so long now - and due to your Vee-Hive-background, I counted you in automatically already... sorry. :-)

    Olaf

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

    Re: VB6 - DirectShow WebCam Minimal Code

    That's fine. I've been looking forward to the day that vbRichClient tackles DirectShow but didn't like to ask! ;-)
    If you don't know where you're going, any road will take you there...

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

  4. #44

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    I might be able to help a little, but right now I have a contract that is eating up a lot of my time. I'll look for the new thread and try to contribute where I can.

    I haven't followed how vbRichClient has progressed but I'm not sure a single gigantic DLL with a mixed bag of things in it meets everyone's needs. Perhaps I haven't given the idea enough thought but I prefer things to be more granular.

    I have a hard time "selling" the idea of projects dependent on large 3rd party libraries. My clients have been bitten badly before by such things.

  5. #45
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by dilettante View Post
    I might be able to help a little, but right now I have a contract that is eating up a lot of my time. I'll look for the new thread and try to contribute where I can.
    Ok - just in case... this new DirectShow-wrapper-stuff will not have a RichClient-dependency... ;-)

    Quote Originally Posted by dilettante View Post
    I haven't followed how vbRichClient has progressed but I'm not sure a single gigantic DLL with a mixed bag of things in it meets everyone's needs. Perhaps I haven't given the idea enough thought but I prefer things to be more granular.
    As for "giving the idea enough thought" - please do ...
    - when you write "single gigantic DLL with a mixed bag of things" - then think: "VB-Runtime-alternative"
    (-> msvbvm60.dll is pretty much the same "mixed bag", containing beside the "compiler-runtime-functions" also
    - a Form- and a UserControl-engine with dynamic-add/remove,
    - a GDI-based drawing-engine supported on different "Canvases",
    - a set of Controls, a Collection and a few other classes I've perhaps forgot).

    The RichClient-development aims at replacing the msvbvm60.dll in the long-run completely.
    Because of that it is based on platform-independent libs already (in its two most "weighty" parts; the DB-engine and the Rendering- and Control-engine).

    As for Deployment-size (in modern LZMA-format, 7zip-archived):
    VBRuntime: msvbvm60.7z = 519KByte
    RichClient: RC5BaseDlls.7z = 1634KByte - so roughly 1MB more "to ship or to download" (which is still OK these days for the "bunch of additional class-functionality")

    Quote Originally Posted by dilettante View Post
    I have a hard time "selling" the idea of projects dependent on large 3rd party libraries. My clients have been bitten badly before by such things.
    You mean "large 3rd party libs" as in e.g.: ... 'ADO' for example? ;-)

    Just joking - but I think you see where I'm getting at ...
    I mean, there *were* some problems with ADO-typelibs, caused by "the vendor" ...
    and wellknown fixes for that in the meantime too - sure - but then... same thing recently with the CommonCtls...

    Not sure what could go wrong in case of a RichClient-dependency in this regard ... what you (or your customers) should fear?
    MS would need to break COM completely - to prevent the instantiation of COM-classes from the RichClient - but in this case no VBClassic-App would work anymore.
    I'm the last person who has an interest in "breaking VBClassic-Apps" - and a bit of trust with regards to:
    "Stuff from Schmidt" should be there in the VBClassic-community I hope (maybe not yet in this forum here, but I'm working to change that <g>)...

    But before getting more Off-Topic - maybe we should continue per Mail?

    It's just - there's a lot of still enthusiastic and young developers here in the Forum (to my surprise, being a late-comer to the party here).
    Young guns, who have loads more "coding-power-per-day" compared to us middle-aged or "already somewhat older" devs who have to "make good with experience".

    I'd like when more experienced VBClassic-devs would join the efforts to come up with a new IDE and a new Compiler
    (sharing in the help-efforts of "channelizing and directing the enthusiasm of the younger devs" a bit).

    So, yeah - I'd like when you could throw your weight into the idea as well - and as for "daily work" -
    I'm moving slowly with all that too (as my spare-time allows) - but every year there's more groundwork done.
    As said, a mail would be nice - maybe I'm able to convince you finally... :-)

    Olaf

  6. #46

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by Schmidt View Post
    - when you write "single gigantic DLL with a mixed bag of things" - then think: "VB-Runtime-alternative"...

    The RichClient-development aims at replacing the msvbvm60.dll in the long-run completely.
    Yeah, I thought this might be the direction.

    Quote Originally Posted by Schmidt View Post
    You mean "large 3rd party libs" as in e.g.: ... 'ADO' for example? ;-)
    Well Microsoft did indeed recently cause some ADO grief (Win7 SP1 comes to mind) but I was thinking of large sets of 3rd party controls you can't get anymore.

    Quote Originally Posted by Schmidt View Post
    I'm the last person who has an interest in "breaking VBClassic-Apps" - and a bit of trust with regards to:
    "Stuff from Schmidt" should be there in the VBClassic-community I hope (maybe not yet in this forum here, but I'm working to change that <g>)...
    Er, don't point at those UseNet groups if you want credibility. A veritiable Mos Eisley Space Port of the worst VB6 programmers in the universe in recent years.

    Quote Originally Posted by Schmidt View Post
    But before getting more Off-Topic - maybe we should continue per Mail?
    Thanks for the invitation, perhaps once I get more settled. I'm doing a lot of travel these days chasing contract work, and mostly come in here instead of vegetating watching television while sitting in motel rooms.

    I'm not sure how else you might move forward though. VB Classic (A True VB 7.0) has been started though your goals may differ and I'm not sure how the rules work for threads in that forum.

    But I will give it more thought.

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

    Re: VB6 - DirectShow WebCam Minimal Code

    As for "not pointing at those Usenet-groups if you want credibility"...

    You're probably right with your "Mos Eisley Space Port"-analogy (the UseNet as a whole goes this route... sadly, I might add).
    But that this automatically would imply an: "only the worst programmers imaginable post there" - I'd doubt.
    I mean, 'Nobody' could reach your conclusion here, if not from occasional UseNet-lurking: ;-)

    Quote Originally Posted by dilettante View Post
    If that Schmidt guy takes an interest he might have more detail to contribute. He dives deeper into COM and VB issues than most of us need to.
    Sorry to dig that up, but a bit of "self-defense" is in order I think...? :-)

    I'm not sure how else you might move forward though. VB Classic (A True VB 7.0) has been started though your goals may differ and I'm not sure how the rules work for threads in that forum.
    Just posted a reply in the thread you linked to - maybe we can continue the discussion (about "RichClient and stuff") there - because I've always seen (and developed) it in this larger context.


    Olaf

  8. #48

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Nothing to defend against.

    You can find anything anywhere. My only point was that the VB newsgroups are dominated by people who don't ever seem to get very good at programming, almost as if nobody else will have them. I wasn't implying that anyone who ever posted there is hopeless though. There is just a bit of a reputation there.

  9. #49
    New Member
    Join Date
    Jul 2013
    Posts
    8

    Re: VB6 - DirectShow WebCam Minimal Code

    It's Expert-to-Expert talking here
    Count me in as one of your followers.

    About my problem from this thread (Saving webcam video to AVI.. Capturing while Recording),
    I'm resting my case. Olaf Schmidt's sample code is the answer though i can't figure what to do.
    I can't figure how to "assemble/extract" that part where the codes remaining in the program(Dilettante's DSMini2)
    are those that solve my problem..

    I don't want to bother any of you guys since you have a more important things to take care of.
    It's going to be too much if i still ask you to do it for me.
    I'll continue playing with Olaf's code until i solve my problem.

    BTW, Dilettante's sample code is very important.
    It was an eye-opener for me to see other experts work like Olaf and ColinE66.

    Lastly, to Olaf: i didn't use bold letters anymore but praises, yes. You all deserve it.
    Thank You A Lot.

    Red

  10. #50

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Using the MS Video Control 1.0 Typelib is an eye-opener for me too. I've never done much with DirectShow and that little was a long time ago, so I was just trying to see what results I could get. My failure to mention it merely means I was completely ignorant of this second typelib, and wish I'd done more research in the first place.

    I hope when I'm back home from my current "road show" I can take time to play with this a little bit again.

    This was sort of a "Beginner's Introduction to DirectShow" code example thread. Maybe now we need an "Intermediate DirectShow" thread?
    Last edited by dilettante; Jul 31st, 2013 at 11:47 PM.

  11. #51
    New Member
    Join Date
    Jul 2013
    Posts
    8

    Re: VB6 - DirectShow WebCam Minimal Code

    When will your current "road show" finish Dilettante? Will it take long?

    if there will be an "Intermediate DirectShow" thread started by you, i'm thanking you in advance.
    i doubt if Schmidt and ColinE66 will still see "that thread" because they're now busy contemplating
    with a "new version" of VB6 Classic with other heavy experts. Are you joining Dilettante?

    Well, back to the intermediate thread, i'm looking forward to seeing it in action

  12. #52
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 - DirectShow WebCam Minimal Code

    I'd like when I could open it with what I currently have with regards to the outlined Class-Structures from one of my posts above ...
    @Colin - the cSampleGrabber is already working - but what is still missing is a cMediaType-implementation, to be able to comfortably
    read-out and apply those settings on cPins who support this (to force certain resolutions and color-spaces)...

    Can't tell when this will finally be finished...(maybe this week, maybe in two) - am currently a bit in a Round-Robin-Mode
    (with short-outbursts here into the forum <g>).

    But if dilettante or Colin already have something new, worthwhile enough to make a (somewhat enhanced) demo from -
    no need to wait for me - I'll join you then.

    Olaf

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

    Re: VB6 - DirectShow WebCam Minimal Code

    Most of my exposure to DirectShow has come about through my use of Geraint Davies' DLL's (fsfwrap, ovtool, and capstill). I am by no means an expert with the underlying DirectShow frame-work, although I am familiar with some of it in an 'if only VB6 had access to that' kind of way; I mean, it's all there just waiting for somebody (Olaf!) to expose it! Having said that, I am happy to contribute to an intermediate VB6 tutorial if dilettante expands upon what he has in mind for it to cover. I'm fine with graph-building, pin and filter enumerations etc. and can certainly contribute something in that respect.

    @Olaf, is there anything that is currently 'usable' (notwithstanding the absence of cMediaType) that I can play around with, please? Oh, and is a cOverlay class planned?
    Last edited by ColinE66; Aug 6th, 2013 at 12:35 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

  14. #54

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by redp View Post
    When will your current "road show" finish Dilettante? Will it take long?
    I have to finish out this week here, then get to another customer's site and spend 3 days there. Then back home to work on things from there... then back to those sites, and so on.

    I'm tied up quite a bit for a while, great news since it means a little money coming in. But for a while I won't be doing anything with VB6 except poking around to read questions here and make short replies in my spare time.

    Quote Originally Posted by redp View Post
    if there will be an "Intermediate DirectShow" thread started by you, i'm thanking you in advance.
    i doubt if Schmidt and ColinE66 will still see "that thread" because they're now busy contemplating
    with a "new version" of VB6 Classic with other heavy experts. Are you joining Dilettante?
    Right now most of my time is taken up with Android projects. I don't do any Windows programming anymore except for recreation unless I get a specific contract to do some Windows programming.

    Right now I don't plan on writing more about DirectShow. I don't have enough experience with it to do a good job anyway.

    I'll keep an eye on the "future VB" thread but I can't contribute right now.

  15. #55
    New Member
    Join Date
    Jul 2013
    Posts
    8

    Re: VB6 - DirectShow WebCam Minimal Code

    So you're moving back and forth Dilettante.. That really takes time and effort. Why not use the power of "networking" in order for you not to go to your project site physically?

    I just paused before typing this to pray that you, Olaf and ColinE66 will get huge projects in the near future and with huge amounts of course.. You all deserve to "get profits" because of your share/contributions on programming not to mention VB forums and the like..

    And since you need to focus doing your projects, maybe this is the end of this thread.

    Your fellow expert's replies from this thread will be read by other beginners in the future.. and will remember the names like Dilettante, Olaf Schmidt and ColinE66..

  16. #56
    New Member
    Join Date
    Mar 2015
    Posts
    3

    Re: VB6 - DirectShow WebCam Minimal Code

    Hi everyone
    Sorry for my poor english.
    I am using windows 7. I try to show webcam on my vb6 form. I am using DSMini4.zip. It is working on my labtop without any problem. My labtop has embeded webcam. It works also I plug other webcam it work too. But when I plug same webcam to other desktop computer the program give a message "builtgraph error". How can I solve this problem. Thank You

  17. #57

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Building the filter graph is the biggest problem faced when using this approach.

    The code posted above tries to stich one together at runtime but it isn't perfect. Success can vary quite a bit from machine to machine, because not every machine has the same set of filters installed.

    For all I know... it may be impossible to write a generic program to do this successfully on every PC even when using exactly the same webcam.

  18. #58
    New Member
    Join Date
    Mar 2015
    Posts
    3

    Re: VB6 - DirectShow WebCam Minimal Code

    Thank you for your reply.
    Are there any solution for using any other machines same program? Can I set filters or something else to run other machines?

  19. #59

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Often the filters can be installed as part of installing video codec packages. There are some filter packages like DirectShow FilterPack 5.1 but i have not used them, and I couldn't say whether they contain the necessary filters.

  20. #60
    New Member
    Join Date
    Mar 2015
    Posts
    3

    Re: VB6 - DirectShow WebCam Minimal Code

    Thank you for your information. When I try it, give my experience to you.

  21. #61
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by tilki View Post
    Hi everyone
    Sorry for my poor english.
    I am using windows 7. I try to show webcam on my vb6 form. I am using DSMini4.zip. It is working on my labtop without any problem. My labtop has embeded webcam. It works also I plug other webcam it work too. But when I plug same webcam to other desktop computer the program give a message "builtgraph error". How can I solve this problem. Thank You
    Download and install K-Lite Codec pack will solve your problem.

  22. #62
    New Member
    Join Date
    Jun 2015
    Posts
    3

    Re: VB6 - DirectShow WebCam Minimal Code

    Hi, This is excellent. Is there a way to capture physical button press of a camera to capture?

    Quote Originally Posted by dilettante View Post
    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.

  23. #63
    New Member
    Join Date
    Jun 2015
    Posts
    3

    Re: VB6 - DirectShow WebCam Minimal Code

    Hi Is there a way to extend this to capture image based on physical button press of a camera?

  24. #64

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    This has nothing to do with still cameras, so you'd want to look at WIA 2.0 or something else. Even then I don't believe there is any communication between a still camera and the PC when the "shutter release" button is pressed.

  25. #65
    New Member
    Join Date
    Jun 2015
    Posts
    3

    Re: VB6 - DirectShow WebCam Minimal Code

    Hi, my camera was a medical imaging camera. It is not a shutter release camera. Software it came with also uses DirectShow and was able to capture it when camera button is pressed. Any chance we could do similar to their software?

  26. #66
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: VB6 - DirectShow WebCam Minimal Code

    3rd party DLL to wrap the extra functions in? Has anybody done that yet?

  27. #67
    New Member
    Join Date
    Oct 2015
    Posts
    3

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by dilettante View Post
    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.
    Hi Dilettante,

    Thanks so much for this, this is the only good DirectShow - VB6 I was able to find. I would like to implement some of your code into Excel using VBA. I have an Excel input form, and I would like users to be able to take a snapshot from webcam video steam, (the snapshot will be stored in an embedded Active X image control). I am having a little trouble extracting the DirectShow part of the code to implement it. I am hoping you can provide some guidance on that. Thanks in advance.

  28. #68

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Hello -

    I'm not a VBA guy, but from what I could tell trying to bang around a bit in Excel and then trying a few web searches for ideas I can see a few issues that might get in your way.

    For one thing you don't have UserControls in most VBA hosts (e.g. Excel) so you'd have to "unwrap" my UserControl code to work directly within a UserForm. However UserForms don't give you access to their hWnd (at least in old Excel 2003 that I have) so you're stuck right there because the video preview window will need it set as its Owner window.

    So from where I'm sitting you'd have to extract parts of my code to make an OCX in VB6 that could be used by Excel as a video preview control.

    Somebody with more experience trying to squeeze more from Excel might have a better option, but that's all I can think of right now. But the good news (?) is that almost everything but the DSPreview.ctl is more or less plain old VB code that should be doable in VBA UserForms, Classes, etc.

  29. #69
    New Member
    Join Date
    Oct 2015
    Posts
    3

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by dilettante View Post
    Hello -

    I'm not a VBA guy, but from what I could tell trying to bang around a bit in Excel and then trying a few web searches for ideas I can see a few issues that might get in your way.

    For one thing you don't have UserControls in most VBA hosts (e.g. Excel) so you'd have to "unwrap" my UserControl code to work directly within a UserForm. However UserForms don't give you access to their hWnd (at least in old Excel 2003 that I have) so you're stuck right there because the video preview window will need it set as its Owner window.

    So from where I'm sitting you'd have to extract parts of my code to make an OCX in VB6 that could be used by Excel as a video preview control.

    Somebody with more experience trying to squeeze more from Excel might have a better option, but that's all I can think of right now. But the good news (?) is that almost everything but the DSPreview.ctl is more or less plain old VB code that should be doable in VBA UserForms, Classes, etc.
    Thanks for your response, you can extend the capability of a VBA userform using Windows API. Please see the following link. http://www.cpearson.com/excel/formcontrol.aspx

    The thing I am struggling with is not fully understanding the implementation of the code, I am thinking it is mostly due to "obscuring" but UI stuff like you have mentioned.

  30. #70

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by doudou View Post
    Thanks for your response, you can extend the capability of a VBA userform using Windows API. Please see the following link. http://www.cpearson.com/excel/formcontrol.aspx
    Yeah, I've seen that Pearson hack but I don't care for it at all. Window spelunking is an act of desperation at best, and it can easily return the hWnd of the wrong window. It's a "by guess and by golly" approach and hardly a real fix.

    But sometimes beggars can't be choosers. I don't have a better suggestion.


    Well it has been a while since I last visited this topic in any seriousness. I decided to try starting more or less from scratch and see how much I could strip it down.

    Along the way I think I figured out how to eliminate the problematic manual Filter Graph construction. This approach should be easier and require less camera-by-camera configuration. At least it seems to adapt nicely to the two very different USB webcams I have here with me at the moment.

    It still needs FSFWrap, so see Visual Basic Questions for the download. It also makes use of my DSDib2Pic.bas module that I think could be a lot cleaner but right now I don't have time to investigate a cleanup of that.

    There are also a few gyrations here that (1.) resize things to fit the video capture dimensions, and (2.) allow the capture properties (including size) to be changed from their defaults. However this demo doesn't try to persist any settings at all, so each run you must choose a camera, even if you only have one connected at the time.

    I also noted that one of the webcams I have right here sometimes comes up under a specific name, and other times comes up as "USB Video Device" - a generic name. This seems to change when I disconnect and later reconnect the webcam to a USB port. Weird, but something to watch out for if you need to persist settings.


    Hopefully this will be a little more helpful.
    Attached Files Attached Files

  31. #71

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    As a caution: this new program above could be problematic if you have a webcam that defaults to a large picture size. The program tries to put the preview window and a "snapshot" Image control side-by-side at the capture size and size the Form to fit and center it within the default monitor.

    So it is possible for it to size the Form such that you can't get to the control widgets in the caption bar's corners since they can end up off-screen.

    You could modify the program to do some scaling to keep things in reasonable proportion.

  32. #72
    New Member
    Join Date
    Oct 2015
    Posts
    3

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by dilettante View Post
    Yeah, I've seen that Pearson hack but I don't care for it at all. Window spelunking is an act of desperation at best, and it can easily return the hWnd of the wrong window. It's a "by guess and by golly" approach and hardly a real fix.

    But sometimes beggars can't be choosers. I don't have a better suggestion.


    Well it has been a while since I last visited this topic in any seriousness. I decided to try starting more or less from scratch and see how much I could strip it down.

    Along the way I think I figured out how to eliminate the problematic manual Filter Graph construction. This approach should be easier and require less camera-by-camera configuration. At least it seems to adapt nicely to the two very different USB webcams I have here with me at the moment.

    It still needs FSFWrap, so see Visual Basic Questions for the download. It also makes use of my DSDib2Pic.bas module that I think could be a lot cleaner but right now I don't have time to investigate a cleanup of that.

    There are also a few gyrations here that (1.) resize things to fit the video capture dimensions, and (2.) allow the capture properties (including size) to be changed from their defaults. However this demo doesn't try to persist any settings at all, so each run you must choose a camera, even if you only have one connected at the time.

    I also noted that one of the webcams I have right here sometimes comes up under a specific name, and other times comes up as "USB Video Device" - a generic name. This seems to change when I disconnect and later reconnect the webcam to a USB port. Weird, but something to watch out for if you need to persist settings.


    Hopefully this will be a little more helpful.
    This is great, thanks a lot.

  33. #73

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Pretty much as expected, the old DIB-to-StdPicture logic had some issues. I was never happy with it and upon re-examination I even found some glaring GDI handle leaks and such.

    Here is one more run at the whole thing again. Basically it changes nothing from the last example I posted just above except:

    • The Form is now a fixed-size Form of about 970 pixels width. This should help when testing a webcam supporting hi-res video dimensions.
    • The webcam preview window is fixed in width at about 640 pixels. Really part of the fixed-Form stuff.
    • The "snapped" picture view is a PictureBox scaled to 50% of the preview to save on Form size. Really part of the fixed-Form stuff.
    • The DIB-to-StdPicture logic has been rewritten to be a little cleaner and take care of some flaws in its GDI handling and to return error information.


    Almost nothing in the DirectShow logic has been altered, so this version really is quite similar to the previous except for the fixed Form size stuff and the improved DIB to StdPicture code.
    Attached Files Attached Files

  34. #74

    Thread Starter
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: VB6 - DirectShow WebCam Minimal Code

    Here's my last version of this (I think).

    • Cleaned up DIB fetch thanks to a trick to request required size. When porting to VBA be cautious with this.
    • Optimized StdPicture creation using SetDIBits instead of MoveMemory.
    • Pause/Run on snap to optimize snap-shotting - almost no "blink" now except when Aero is active.
    • Added save to disk as JPEG.
    Attached Files Attached Files

  35. #75
    Lively Member
    Join Date
    Dec 2010
    Posts
    69

    Re: VB6 - DirectShow WebCam Minimal Code

    ----
    Last edited by tmighty; Feb 2nd, 2016 at 01:01 PM.

  36. #76
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: VB6 - DirectShow WebCam Minimal Code

    bummer, it's too bad the source for FSWrapper wasn't available. It shouldn't be too hard to come up with a VB Compatible typelib, to implement the needed classes in VB.

  37. #77
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by DEXWERX View Post
    bummer, it's too bad the source for FSWrapper wasn't available. It shouldn't be too hard to come up with a VB Compatible typelib, to implement the needed classes in VB.
    Did you see the Demo I've posted in #38?
    It replaces already most of the functionality of the FSWrapper with other typelibs (which come preinstalled on the system).

    Olaf

  38. #78
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,224

    Re: VB6 - DirectShow WebCam Minimal Code

    Quote Originally Posted by Schmidt View Post
    Did you see the Demo I've posted in #38?
    It replaces already most of the functionality of the FSWrapper with other typelibs (which come preinstalled on the system).

    Olaf
    That's perfect, Olaf. Thanks.

  39. #79
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: VB6 - DirectShow WebCam Minimal Code

    Have you found a solution to this complete lack of VB6 support in quartz.dll, that would allow a VB6 programmer full access to the entirety of the DirectShow framework? I think you can access it all with VC++. Has anybody yet bothered to create a VB6 friendly wrapper (preferably an ActiveX DLL file, or at least an STDCALL DLL File) in VC++, that gives VB6 users the full power of DirectShow? If so, where can I download this DLL file?

  40. #80
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,647

    Re: VB6 - DirectShow WebCam Minimal Code

    Hmm looks like it's high time to go and make a TLB with all the DirectShow interfaces like I just did for Core Audio. Saw this example then saw how easy ICaptureGraphBuilder2 makes capturing**...

    The quartz.dll this project uses seems to have extremely few of the interfaces... is there a more thorough one before I go off on another massive interface conversion expedition?

    Is there a particular reason a DLL is being used? Do the interfaces require some sort of background code that a TLB wouldn't support?

    -----
    * I was looking at this code... if I made such a TLB in a VB friendly form like usual, it looks like an easy direct translation:
    Code:
    #include <dshow.h>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char* argv[])
    {
      CoInitialize(NULL);
    
      // 1. フィルタグラフ作成
      IGraphBuilder *pGraph = NULL;
      CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
          IID_IGraphBuilder, (void **)&pGraph);
    
      // 2. システムデバイス列挙子を作成
      ICreateDevEnum *pDevEnum = NULL;
      CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC,
          IID_ICreateDevEnum, (void **)&pDevEnum);
    
      IEnumMoniker *pClassEnum = NULL;
      pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pClassEnum, 0);
    
      ULONG cFetched;
      IMoniker *pMoniker = NULL;
      IBaseFilter *pSrc = NULL;
      if (pClassEnum->Next(1, &pMoniker, &cFetched) == S_OK){
        // 最初のモニカをフィルタオブジェクトにバインドする
        pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void **)&pSrc);
        pMoniker->Release();
      }
      pClassEnum->Release();
      pDevEnum->Release();
    
      pGraph->AddFilter(pSrc, L"Video Capture");
    
      // 3. キャプチャビルダの作成
      ICaptureGraphBuilder2 *pBuilder = NULL;
      CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC,
          IID_ICaptureGraphBuilder2, (void **)&pBuilder);
      pBuilder->SetFiltergraph(pGraph);
      
      // 4. ファイルライタフィルタの設定
      IBaseFilter *pMux = NULL;
      IFileSinkFilter *pSink = NULL;
    
      // ファイルへ
      pBuilder->SetOutputFileName(&MEDIASUBTYPE_Avi, L"C:\\dvcap_tmp.avi", &pMux, &pSink);
      pBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, pSrc, NULL, pMux);
      REFERENCE_TIME rtStart = 50000000, rtStop = 80000000;
      pBuilder->ControlStream( &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, pSrc, &rtStart, &rtStop,
          0, 0 );
      // ディスプレイへ
      pBuilder->RenderStream( &PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pSrc, NULL, NULL );
    
    
      // 5. キャプチャ開始
      IMediaControl *pMediaControl;
      pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
      pMediaControl->Run();
    
      MessageBox(NULL, "Click to stop.", "DirectShow", MB_OK);
      
      // 6. 終了
      pSrc->Release();
      pMux->Release();
      pSink->Release();
      pMediaControl->Release();
      pEvent->Release();
      pBuilder->Release();
      pGraph->Release();
      CoUninitialize();
    
      cout << "end\n";
      return 0;
    }
    Last edited by fafalone; May 22nd, 2016 at 02:15 AM.

Page 2 of 4 FirstFirst 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