[python-win32] Using DirectShow API to access webcam

Joe solarjoe at posteo.org
Fri Aug 17 02:09:06 EDT 2018


Hello Tim,

thanks for your helpful answer and the explanations.
Following up on your comment on http://videocapture.sourceforge.net/
I found that there is jaraco.video, which seems to be
"a port of the VideoCapture module in pure Python using ctypes and 
comtypes."
(https://github.com/jaraco/jaraco.video)

It is using a 'DirectShow.tlb' file, whatever that is, to get the
definitions into comtypes.

https://github.com/jaraco/jaraco.video/blob/master/jaraco/video/api/__init__.py#L35

https://github.com/jaraco/jaraco.video/blob/master/jaraco/video/api/objects.py#L9

If your interested, I will post my progress on SO.

Kind regards,
Joe



> 
> An "interface" in COM terms, described by an IID, is just a set of
> functions declarations.  It defines the things you can do with an
> object, but it is not actually an object.  A "CLSID", on the other
> hand, defines a COM object.  The CLSID doesn't tell you what the
> object can do, it's just a way of creating an object.  Once you have
> used a CLSID to create an object, you can ask it for an interface.
> 
> So, you can't just create IID_IAMVideoProcAmp.  You have to ask an
> existing object for its IAMVideoProcAmp interface.  You would create
> your camera object, and then query the camera object for
> IAMVideoProcAmp.
> 
> Creating a DirectShow graph is a multi-step process.  You create a
> filter graph, you add your camera to the graph, you tell the graph to
> render the stream (which means it automatically fills in the other
> filters), and you control it.  Here is some sample code that does
> this:
> 
>     https://gist.github.com/dust8/3890196
> 
> This is actually more complicated than it needs to be, because it's
> trying to handle TV devices with tuner and audio filters as well. You
> don't need that.  Once you have a device from
> VideoInputDeviceCategory, you don't need the video decoder or the
> audio.  You can just render the graph at that point.
> 
> Alternatively, it looks like this package might be more applicable:
> 
>     http://videocapture.sourceforge.net/
> 
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> https://mail.python.org/mailman/listinfo/python-win32


More information about the python-win32 mailing list