Directshow in Python

S

Sayanan Sivaraman

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
 
T

Thomas Heller

Sayanan said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top