By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

wxPython Video Capture using ActiveX (OCX) Control

bartonc
Expert 5K+
P: 6,596
I just got video capture working in my wxPython project, if any one is interested.
Another really cool thing that I got working tonight is Boa Constructor _Custom_Classes, which allow my video window to be displayed in the Designer window. Very handy!
Aug 17 '07 #1
Share this Question
Share on Google+
6 Replies


P: 5
I'm extremely interested, just setting out to do this same sort of thing, any little bit would help.

Thanks if possible, hopefully you'll see this....
Dec 4 '07 #2

bartonc
Expert 5K+
P: 6,596
I'm extremely interested, just setting out to do this same sort of thing, any little bit would help.

Thanks if possible, hopefully you'll see this....
OK. How familiar with wxPython are you?

I ended up purchasing an ActiveX control from Russia for $60 US but I'm not really allowed to link to commercial sites here. You'll find many such goodies by Googling "ActiveX video capture". The one I chose is called ELVideoCapture. My favorite one was from Germany, but didn't seem to have much support, hadn't been updated in a while and was much more expensive. I'd stay way from XVideoOCX. The product is OK, but the support team only knows VB.
Dec 4 '07 #3

P: 5
I'm very familiar with wxPython, but not very familiar with ActiveX. I don't imagine you have a moment to write a primer on that?

I've been experimenting with capturing video using the videocapture module (http://videocapture.sourceforge.net/), which works well enough, and returns a PIL instance, which is great. But so far I'm writing each JPG to the harddrive as its capture, which is of course slow. On my computer I'm getting about 13fps maximum.

I'm then stitching together with mencoder.

Issues:

- how to display the images as they're captured? That's something I need to do, which is where wx will come in.

- how to increase the FPS?

- how to do sound capture?
Dec 5 '07 #4

bartonc
Expert 5K+
P: 6,596
I'm very familiar with wxPython, but not very familiar with ActiveX. I don't imagine you have a moment to write a primer on that?

I've been experimenting with capturing video using the videocapture module (http://videocapture.sourceforge.net/), which works well enough, and returns a PIL instance, which is great. But so far I'm writing each JPG to the harddrive as its capture, which is of course slow. On my computer I'm getting about 13fps maximum.

I'm then stitching together with mencoder.

Issues:

- how to display the images as they're captured? That's something I need to do, which is where wx will come in.

- how to increase the FPS?

- how to do sound capture?
One answer: ActiveX will take care of all the performance, sound?, etc. issues.
The wx.lib has all that you will need. Here is one of my early tests. the vb thing was a trial download:
Expand|Select|Wrap|Line Numbers
  1. #Boa:Frame:Frame1
  2.  
  3. import wx
  4. import wx.activex as ActiveX
  5.  
  6.  
  7. ## From OLE Object Viewer ##
  8. guidStr = "{DF6D6569-5B0C-11D3-9396-008029E9B3A6}"
  9.  
  10. ## make wx compatible ##
  11. CLSID_vbVidC60 = ActiveX.CLSID(guidStr)
  12. name = "vbVidC60"
  13.  
  14. ### post gen #
  15. ##from vbVidC60 import vbVidC60
  16.  
  17. def create(parent):
  18.     return Frame1(parent)
  19.  
  20. [wxID_FRAME1, wxID_FRAME1WINDOW1, 
  21. ] = [wx.NewId() for _init_ctrls in range(2)]
  22.  
  23. class Frame1(wx.Frame):
  24. ##    _custom_classes = {'wx.Window': ['vbVidC60']}
  25. ##    def _init_sizers(self):
  26. ##        # generated method, don't edit
  27. ##        self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)
  28. ##
  29. ##        self._init_coll_boxSizer1_Items(self.boxSizer1)
  30. ##
  31. ##        self.SetSizer(self.boxSizer1)
  32. ##
  33. ##
  34. ##    def _init_coll_boxSizer1_Items(self, parent):
  35. ##        # generated method, don't edit
  36. ##
  37. ##        parent.AddWindow(self.window1, 1, border=0, flag=wx.EXPAND)
  38. ##
  39. ##    def _init_ctrls(self, prnt):
  40. ##        # generated method, don't edit
  41. ##        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(198, 198),
  42. ##                size=wx.Size(400, 250), style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
  43. ##        self.SetClientSize(wx.Size(392, 223))
  44. ##
  45. ##        self.window1 = vbVidC60(ID=wxID_FRAME1WINDOW1, name='window1', parent=self, pos=wx.Point(0,
  46. ##                0), size=wx.Size(392, 223), style=0)
  47. ##
  48. ##        self._init_sizers()
  49.  
  50.     def __init__(self, parent):
  51. ##        self._init_ctrls(parent)
  52. ##        self.window1.autosize = False
  53. ##        print self.window1.NumCapDevs()
  54. ##        print self.window1.driverindex
  55.  
  56.  
  57. ##        try:
  58.         vidwin = ActiveX.ActiveXWindow(self, CLSID_vbVidC60, -1, wx.DefaultPosition,
  59.                                        wx.DefaultSize, 0, name)
  60.  
  61.         print "Generating %s from CLSID %s" %(name, guidStr)
  62.         print "!!!!!!"
  63.         dummy = ActiveX.GernerateAXModule(vidwin, name, ".", None, True)
  64.         print "!!!!!!"
  65. # I don't remember why the next line was here:
  66. ##        vidwin.Destroy()
  67.         print "!!!!!!"
  68. ##        except Exception, e:
  69. ##            print "Couldn't create %s with %s" %(name, guidStr)
  70. ##            print e
  71.  
  72.  
  73. if __name__ == "__main__":
  74.     app = wx.PySimpleApp()
  75.     frame = create(None)
  76.     frame.Show()
  77.     app.MainLoop()
  78.  
Dec 7 '07 #5

P: 5
I'm trying to get this to work, and having problems. It fails when defining vidwin (the ActiveXWindow). Here's my code, adapted from yours, trying to use it with the EL VideoCapture DLL.

Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import wx.activex as ActiveX
  3.  
  4. class Frame1(wx.Frame):
  5.     def __init__(self, parent):
  6.  
  7.         wx.Frame.__init__(self, None , wx.ID_ANY, "Test")
  8.  
  9.         ## make wx compatible ##
  10.         #guidStr = "{DF6D6569-5B0C-11D3-9396-008029E9B3A6}" # string for EZVidCap5
  11.         guidStr = "{16761F2C-934F-4851-8897-DC01F46253C8}" # string for ELVideoCapture?
  12.         CLSID_ELVidCap = ActiveX.CLSID(guidStr)
  13.         name = "vbVidC60"
  14.  
  15.         vidwin = ActiveX.ActiveXWindow(self, CLSID_ELVidCap, -1, wx.DefaultPosition, wx.DefaultSize, 0, name)
  16.  
  17.         print "Generating %s from CLSID %s" %(name, guidStr)
  18.         print "!!!!!!"
  19.         dummy = ActiveX.GernerateAXModule(vidwin, name, ".", None, True)
  20.         print "!!!!!!"
  21.  
  22.         self.Show()
  23.  
  24. app = wx.App(redirect=0)
  25. Frame1(None)
  26. app.MainLoop()
  27.  
It fails like this:

Expand|Select|Wrap|Line Numbers
  1. C:\Python24>activecapture.py
  2. Traceback (most recent call last):
  3.   File "C:\Python24\activecapture.py", line 29, in ?
  4.     Frame1(None)
  5.   File "C:\Python24\activecapture.py", line 17, in __init__
  6.     vidwin = ActiveX.ActiveXWindow(self, CLSID_ELVidCap, -1, wx.DefaultPosition, wx.DefaultSize, 0,
  7. name)
  8.   File "C:\Python24\Lib\site-packages\wx-2.8-msw-unicode\wx\activex.py", line 226, in __init__
  9.     _activex.ActiveXWindow_swiginit(self,_activex.new_ActiveXWindow(*args, **kwargs))
  10. wx._core.PyAssertionError: C++ assertion "m_ActiveX.Ok()" failed at contrib\activex\wxie/wxactivex.c
  11. pp(323) in wxActiveX::CreateActiveX(): m_ActiveX.CreateInstance failed
  12.  
I'm not at all sure if I'm doing anything correctly with EL VideoCapture. After installing it, I registered the DLL (I think) like this, which appeared to be successfull:

Regsvr32 ELVideoCapture.dll

When I run tools --> Com MakePy Utility from PythonWin, the ELVideoCapture.dll does show up. I then open the file in gen_py (called 16761F2C-934F-4851-8897-DC01F46253C8x0x1x0.py) and get the CLSID. I can see all the methods in that file. But alas, I can't initialize it.

Did you use genaxmodule.py?

I don't imagine it'd be possible to post the code that you got working with EL VideoCapture? Or point out some error in my code?

Extremely grateful for any help.
Jan 28 '08 #6

P: 5
I've made some good progress.

I used genaxmodule.py to wrap the EL Videocapture drivers. It produced a module that I uploaded here . Note that I also zipped the output from the Com MakePy Utility, it's the file with the long filename. It has some useful comments.

Anyway, I'm now having an odd problem. I seem to be successfully initializing the DLL, at least the ActiveXWindow is initializing successfully. However WX crashes hard whenever I start capture.

I've been emailing with ELVidcapture tech support, and they gave me different CLSIDs than I'm using. Theirs don't allow me to initialize the window though. So I'm wondering what CLSID you're using?

When I use the following code without registering, it shows the EL Videocapture logo, saying "unregistered". However when I close the window, it crashes. When I register (registration line omitted here since it's my licensing info), it simply crashes. So I don't think I'm initializing things correctly.

Any help would be phenomenal, I'm near wit's end on this.


Expand|Select|Wrap|Line Numbers
  1. import os
  2. import wx
  3. import wx.activex
  4.  
  5. class Frame1(wx.Frame):
  6.     def __init__(self, parent):
  7.  
  8.         wx.Frame.__init__(self, None , wx.ID_ANY, "Test")
  9.  
  10.         self.panel = wx.Panel(self)
  11.  
  12.         wx.EVT_CLOSE(self, self.OnClose)
  13.  
  14.         # CLSID from Com Object Viewer
  15.         clstr = "{84985BC1-BCB3-45E6-9ECF-DC006ACCC1CF}" # the one I got semi working
  16.         #clstr = "{16761F2C-934F-4851-8897-DC01F46253C8}" # they said to use this one or two below, neither work for me
  17.         #clstr = "{BDB13542-5849-4493-8B3E-1371C30E374F}"
  18.         #clstr = "{81FF70E3-AFDD-4618-98AE-A0FF67BBF95C}"
  19.  
  20.         ctrl = wx.activex.ActiveXWindow(self,
  21.                        clsId=wx.activex.CLSID(clstr),
  22.                        id=-1,
  23.                        name="somename"
  24.                        )
  25.  
  26.         import elvidcap
  27.         a = elvidcap.elvidcap(ctrl)
  28.  
  29.         print a.Register("[my name deleted]", "[my license deleted]")
  30.         a.StartPreview() # crash!
  31.  
  32.         # this works:
  33.         for i in range(a.capturedrivercount):
  34.             print a.GetCaptureDriverNameByIndex(i)
  35.  
  36.         self.Show()
  37.  
  38.     # Stuff to do when we exit:    
  39.     def OnClose(self, event):
  40.         print "deleting"
  41.         #a.StopPreview()
  42.         #del a
  43.         print "exiting"
  44.         os._exit(1)
  45.  
  46.  
  47.  
  48. app = wx.App(redirect=0)
  49. Frame1(None)
  50. app.MainLoop()
  51.  
Jan 28 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.