wxPython Video Capture using ActiveX (OCX) Control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    wxPython Video Capture using ActiveX (OCX) Control

    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!
  • wrybread
    New Member
    • Dec 2007
    • 5

    #2
    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....

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by wrybread
      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.

      Comment

      • wrybread
        New Member
        • Dec 2007
        • 5

        #4
        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.so urceforge.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?

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #5
          Originally posted by wrybread
          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:[CODE=python]#Boa:Frame:Fram e1

          import wx
          import wx.activex as ActiveX


          ## From OLE Object Viewer ##
          guidStr = "{DF6D6569-5B0C-11D3-9396-008029E9B3A6}"

          ## make wx compatible ##
          CLSID_vbVidC60 = ActiveX.CLSID(g uidStr)
          name = "vbVidC60"

          ### post gen #
          ##from vbVidC60 import vbVidC60

          def create(parent):
          return Frame1(parent)

          [wxID_FRAME1, wxID_FRAME1WIND OW1,
          ] = [wx.NewId() for _init_ctrls in range(2)]

          class Frame1(wx.Frame ):
          ## _custom_classes = {'wx.Window': ['vbVidC60']}
          ## def _init_sizers(se lf):
          ## # generated method, don't edit
          ## self.boxSizer1 = wx.BoxSizer(ori ent=wx.VERTICAL )
          ##
          ## self._init_coll _boxSizer1_Item s(self.boxSizer 1)
          ##
          ## self.SetSizer(s elf.boxSizer1)
          ##
          ##
          ## def _init_coll_boxS izer1_Items(sel f, parent):
          ## # generated method, don't edit
          ##
          ## parent.AddWindo w(self.window1, 1, border=0, flag=wx.EXPAND)
          ##
          ## def _init_ctrls(sel f, prnt):
          ## # generated method, don't edit
          ## wx.Frame.__init __(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(19 8, 198),
          ## size=wx.Size(40 0, 250), style=wx.DEFAUL T_FRAME_STYLE, title='Frame1')
          ## self.SetClientS ize(wx.Size(392 , 223))
          ##
          ## self.window1 = vbVidC60(ID=wxI D_FRAME1WINDOW1 , name='window1', parent=self, pos=wx.Point(0,
          ## 0), size=wx.Size(39 2, 223), style=0)
          ##
          ## self._init_size rs()

          def __init__(self, parent):
          ## self._init_ctrl s(parent)
          ## self.window1.au tosize = False
          ## print self.window1.Nu mCapDevs()
          ## print self.window1.dr iverindex


          ## try:
          vidwin = ActiveX.ActiveX Window(self, CLSID_vbVidC60, -1, wx.DefaultPosit ion,
          wx.DefaultSize, 0, name)

          print "Generating %s from CLSID %s" %(name, guidStr)
          print "!!!!!!"
          dummy = ActiveX.Gernera teAXModule(vidw in, name, ".", None, True)
          print "!!!!!!"
          # I don't remember why the next line was here:
          ## vidwin.Destroy( )
          print "!!!!!!"
          ## except Exception, e:
          ## print "Couldn't create %s with %s" %(name, guidStr)
          ## print e


          if __name__ == "__main__":
          app = wx.PySimpleApp( )
          frame = create(None)
          frame.Show()
          app.MainLoop()
          [/CODE]
          Last edited by bartonc; Dec 7 '07, 11:09 PM.

          Comment

          • wrybread
            New Member
            • Dec 2007
            • 5

            #6
            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.

            Code:
            import wx
            import wx.activex as ActiveX
            
            class Frame1(wx.Frame):
                def __init__(self, parent):
            
                    wx.Frame.__init__(self, None , wx.ID_ANY, "Test")
            
                    ## make wx compatible ##
                    #guidStr = "{DF6D6569-5B0C-11D3-9396-008029E9B3A6}" # string for EZVidCap5
                    guidStr = "{16761F2C-934F-4851-8897-DC01F46253C8}" # string for ELVideoCapture?
                    CLSID_ELVidCap = ActiveX.CLSID(guidStr)
                    name = "vbVidC60"
                    
                    vidwin = ActiveX.ActiveXWindow(self, CLSID_ELVidCap, -1, wx.DefaultPosition, wx.DefaultSize, 0, name)
            
                    print "Generating %s from CLSID %s" %(name, guidStr)
                    print "!!!!!!"
                    dummy = ActiveX.GernerateAXModule(vidwin, name, ".", None, True)
                    print "!!!!!!"
            
                    self.Show()
            
            app = wx.App(redirect=0)
            Frame1(None)
            app.MainLoop()
            It fails like this:

            Code:
            C:\Python24>activecapture.py
            Traceback (most recent call last):
              File "C:\Python24\activecapture.py", line 29, in ?
                Frame1(None)
              File "C:\Python24\activecapture.py", line 17, in __init__
                vidwin = ActiveX.ActiveXWindow(self, CLSID_ELVidCap, -1, wx.DefaultPosition, wx.DefaultSize, 0,
            name)
              File "C:\Python24\Lib\site-packages\wx-2.8-msw-unicode\wx\activex.py", line 226, in __init__
                _activex.ActiveXWindow_swiginit(self,_activex.new_ActiveXWindow(*args, **kwargs))
            wx._core.PyAssertionError: C++ assertion "m_ActiveX.Ok()" failed at contrib\activex\wxie/wxactivex.c
            pp(323) in wxActiveX::CreateActiveX(): m_ActiveX.CreateInstance failed
            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-DC01F46253C8x0x 1x0.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.

            Comment

            • wrybread
              New Member
              • Dec 2007
              • 5

              #7
              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 "unregister ed". 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.


              Code:
              import os
              import wx
              import wx.activex
              
              class Frame1(wx.Frame):
                  def __init__(self, parent):
              
                      wx.Frame.__init__(self, None , wx.ID_ANY, "Test")
              
                      self.panel = wx.Panel(self)
              
                      wx.EVT_CLOSE(self, self.OnClose)
                      
                      # CLSID from Com Object Viewer
                      clstr = "{84985BC1-BCB3-45E6-9ECF-DC006ACCC1CF}" # the one I got semi working
                      #clstr = "{16761F2C-934F-4851-8897-DC01F46253C8}" # they said to use this one or two below, neither work for me
                      #clstr = "{BDB13542-5849-4493-8B3E-1371C30E374F}"
                      #clstr = "{81FF70E3-AFDD-4618-98AE-A0FF67BBF95C}"
              
                      ctrl = wx.activex.ActiveXWindow(self,
                                     clsId=wx.activex.CLSID(clstr),
                                     id=-1,
                                     name="somename"
                                     )
              
                      import elvidcap
                      a = elvidcap.elvidcap(ctrl)
              
                      print a.Register("[my name deleted]", "[my license deleted]")
                      a.StartPreview() # crash!
              
                      # this works:
                      for i in range(a.capturedrivercount):
                          print a.GetCaptureDriverNameByIndex(i)
              
                      self.Show()
              
                  # Stuff to do when we exit:    
                  def OnClose(self, event):
                      print "deleting"
                      #a.StopPreview()
                      #del a
                      print "exiting"
                      os._exit(1)
              
                      
              
              app = wx.App(redirect=0)
              Frame1(None)
              app.MainLoop()

              Comment

              Working...