Directshow in Python

Discussion in 'Python' started by Sayanan Sivaraman, Sep 18, 2008.

  1. Hey all,

    I'm trying to use DirectShow to display videos [I'm kind of new to
    Python, from more of a C++ background on windows]. I found some
    sample code online, but I am having trouble with calling the I

    import ctypes
    from ctypes import *
    from comtypes import client
    from ctypes.wintypes import *
    import sys
    import time


    filename = sys.argv[1]


    qedit = client.GetModule('qedit.dll') # DexterLib
    quartz= client.GetModule("quartz.dll")


    CLSID_FilterGraph = '{e436ebb3-524f-11ce-9f53-0020af0ba770}'
    filter_graph =
    client.CreateObject(CLSID_FilterGraph,interface=qedit.IFilterGraph)
    filter_builder = filter_graph.QueryInterface(qedit.IGraphBuilder)
    filter_builder.RenderFile(filename, None)

    media_control = filter_graph.QueryInterface(quartz.IMediaControl)
    media_control.Run()

    try:
    # Look at IMediaEvent interface for EOS notification
    while True:
    time.sleep(1)
    except KeyboardInterrupt:
    pass

    # Need these because finalisers don't have enough context to clean up
    after
    # themselves when script exits.
    del media_control
    del filter_builder
    del filter_graph

    This code works fine. What I would like to know, is how do I declare
    filename in the Python program to be of type LPCWSTR, so that I don't
    need to parse the command line in order to call the function
    "RenderFile()"?

    -Sayanan
    Sayanan Sivaraman, Sep 18, 2008
    #1
    1. Advertising

  2. Sayanan Sivaraman schrieb:
    > Hey all,
    >
    > I'm trying to use DirectShow to display videos [I'm kind of new to
    > Python, from more of a C++ background on windows]. I found some
    > sample code online, but I am having trouble with calling the I
    >
    > import ctypes
    > from ctypes import *
    > from comtypes import client
    > from ctypes.wintypes import *
    > import sys
    > import time
    >
    >
    > filename = sys.argv[1]
    >
    >
    > qedit = client.GetModule('qedit.dll') # DexterLib
    > quartz= client.GetModule("quartz.dll")
    >
    >
    > CLSID_FilterGraph = '{e436ebb3-524f-11ce-9f53-0020af0ba770}'
    > filter_graph =
    > client.CreateObject(CLSID_FilterGraph,interface=qedit.IFilterGraph)
    > filter_builder = filter_graph.QueryInterface(qedit.IGraphBuilder)
    > filter_builder.RenderFile(filename, None)
    >
    > media_control = filter_graph.QueryInterface(quartz.IMediaControl)
    > media_control.Run()
    >
    > try:
    > # Look at IMediaEvent interface for EOS notification
    > while True:
    > time.sleep(1)
    > except KeyboardInterrupt:
    > pass
    >
    > # Need these because finalisers don't have enough context to clean up
    > after
    > # themselves when script exits.
    > del media_control
    > del filter_builder
    > del filter_graph
    >
    > This code works fine. What I would like to know, is how do I declare
    > filename in the Python program to be of type LPCWSTR, so that I don't
    > need to parse the command line in order to call the function
    > "RenderFile()"?


    If I understand your question correctly (I'm no sure): comtypes converts
    Python strings or unicode strings to the required LPCWSTR type itself.
    So, you can call
    filter_builder.RenderFile("c:\\windows\\clock.avi", None)
    or
    filter_builder.RenderFile(u"c:\\windows\\clock.avi", None)

    If you pass a string, comtypes converts it to unicode using the "mbcs"
    codec; this can be changed by setting ctypes.conversion_mode.

    Thomas
    Thomas Heller, Sep 19, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. agrsaurabh
    Replies:
    1
    Views:
    476
    Thomas Matthews
    Oct 14, 2003
  2. michael mazanek
    Replies:
    0
    Views:
    796
    michael mazanek
    Sep 17, 2006
  3. Replies:
    0
    Views:
    728
  4. Paul Moore
    Replies:
    0
    Views:
    599
    Paul Moore
    Mar 1, 2008
  5. Sayanan Sivaraman

    python timers and COM/directshow

    Sayanan Sivaraman, Sep 22, 2008, in forum: Python
    Replies:
    4
    Views:
    735
    Sayanan Sivaraman
    Sep 25, 2008
Loading...

Share This Page