示例#1
0
def haswmpruntimecomponents():
    try:
        import wmfapi
        dummy = wmfapi.CreateProfileManager()
    except:
        return 0
    return 1
示例#2
0
 def __init__(self, dds, profile=20):
     self._dds = dds
     self._writer = None
     self._filename = None
     self._sample = None
     self._lasttm = 0
     if not wmfapi:
         return
     profman = wmfapi.CreateProfileManager()
     prof = profman.LoadSystemProfile(profile)
     writer = wmfapi.CreateDDWriter(prof)
     wmtype = wmfapi.CreateDDVideoWMType(self._dds)
     writer.SetVideoFormat(wmtype)
     self._writer = writer
示例#3
0
 def __init__(self, exporter, dds, profile=20):
     self._exporter = exporter
     self._dds = dds
     self._writer = None
     self._filename = None
     self._sample = None
     self._lasttm = 0
     self._writing = 0
     if not wmfapi:
         return
     profman = wmfapi.CreateProfileManager()
     prof = profman.LoadSystemProfile(profile)
     writer = wmfapi.CreateDDWriter(prof)
     wmtype = wmfapi.CreateDDVideoWMType(self._dds)
     writer.SetVideoFormat(wmtype)
     self._writer = writer
     self._audiopeer = dshow.CreatePyRenderingListener(self)
示例#4
0
import wmfapi
large_int = wmfapi.large_int

# init COM libs
wmfapi.CoInitialize()


# temp debug: find the name of a guid
def findguid(guid):
    for s in dir(wmfapi):
        if s.find("WMMEDIA") >= 0 or s.find("WMFORMAT") >= 0:
            if guid == getattr(wmfapi, s):
                return s


profman = wmfapi.CreateProfileManager()
nprofiles = profman.GetSystemProfileCount()
print nprofiles, 'system profiles:'
for ix in range(nprofiles):
    prof = profman.LoadSystemProfile(ix)
    print ix, prof.GetName()

# find audio pin
prof = profman.LoadSystemProfile(10)
writer = wmfapi.CreateWriter()
writer.SetProfile(prof)
npins = writer.GetInputCount()
audiopinix = -1
audiopinmt = None
audiopinprops = None
print 'profile pins:'
示例#5
0
 def createWMWriter(self, profilenum):
     profman = wmfapi.CreateProfileManager()
     profile = profman.LoadSystemProfile(profilenum)
     writer = wmfapi.CreateWriter()
     writer.SetProfile(profile)
     return writer
示例#6
0
def convertaudiofile(url, dstdir, file, node):
    # ignore suggested extension and make our own
    file = os.path.splitext(file)[0] + '.wma'
    fullpath = os.path.join(dstdir, file)

    profman = wmfapi.CreateProfileManager()

    # set an apropriate system profile
    # or a create a new one
    profile = profman.LoadSystemProfile(10)

    # find audio pin
    writer = wmfapi.CreateWriter()
    writer.SetProfile(profile)
    npins = writer.GetInputCount()
    audiopinix = -1
    audiopinmt = None
    audiopinprops = None
    print 'profile pins:'
    for i in range(npins):
        pinprop = writer.GetInputProps(i)
        pintype = pinprop.GetType()
        if pintype == wmfapi.WMMEDIATYPE_Audio:
            audiopinix = i
            audiopinprops = pinprop
            audiopinmt = pinprop.GetMediaType()
    if audiopinix >= 0:
        print 'audiopin is pin ', audiopinix
    else:
        print 'no audio pin'
        return None

    writer.SetOutputFilename(fullpath)

    b = dshow.CreateGraphBuilder()
    import MMurl
    url = MMurl.canonURL(url)
    url = MMurl.unquote(url)
    b.RenderFile(url)
    # find renderer
    try:
        aurenderer = b.FindFilterByName('Default DirectSound Device')
    except:
        aurenderer = None
    if not aurenderer:
        try:
            aurenderer = b.FindFilterByName('Default WaveOut Device')
        except:
            aurenderer = None
    if not aurenderer:
        return None
    enumpins = aurenderer.EnumPins()
    pin = enumpins.Next()
    aulastpin = pin.ConnectedTo()
    b.RemoveFilter(aurenderer)
    try:
        f = dshow.CreateFilter('Audio Windows Media Converter')
    except:
        print 'Audio windows media converter filter is not installed'
        return None
    b.AddFilter(f, 'AWMC')
    b.Render(aulastpin)
    try:
        wmconv = f.QueryIWMConverter()
    except:
        print 'Filter does not support interface IWMConverter'
        return
    try:
        uk = writer.QueryIUnknown()
    except:
        print 'WMWriter QueryIUnknown failed'
        return
    wmconv.SetWMWriter(uk)

    try:
        uk = audiopinprops.QueryIUnknown()
    except:
        print 'WMInputMediaProps QueryIUnknown failed'
        return
    wmconv.SetAudioInputProps(audiopinix, uk)

    # media properties and converting is
    # managed by our dshow filter
    mc = b.QueryIMediaControl()
    mc.Run()
    import sys
    if sys.platform == 'win32':
        # remove messages in queue
        import win32ui
        while b.WaitForCompletion(0) == 0:
            win32ui.PumpWaitingMessages()
        mc.Stop()
        win32ui.PumpWaitingMessages()
    else:
        b.WaitForCompletion()
        mc.Stop()