Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Directshow in Python

Reply
Thread Tools

Directshow in Python

 
 
Sayanan Sivaraman
Guest
Posts: n/a
 
      09-18-2008
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=qe dit.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
 
Reply With Quote
 
 
 
 
Thomas Heller
Guest
Posts: n/a
 
      09-19-2008
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=qe dit.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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python timers and COM/directshow Sayanan Sivaraman Python 4 09-25-2008 07:06 PM
Searching comp.lang.python/python-list@python.org (was: UTF-8) skip@pobox.com Python 0 03-10-2007 02:50 PM
problem with directx & directshow =?Utf-8?B?UGFyYXNpdGU=?= Windows 64bit 0 03-05-2007 06:15 AM
Variant to String. VideoCodec - Friendly name in DirectShow michael mazanek C++ 0 09-17-2006 10:04 AM
(DirectShow) AVI player using CFrameWnd class ??? agrsaurabh C++ 1 10-14-2003 04:18 PM



Advertisments