Exemplo n.º 1
0
 def createWMWriter(self, profilenum):
     profman = wmfapi.CreateProfileManager()
     profile = profman.LoadSystemProfile(profilenum)
     writer = wmfapi.CreateWriter()
     writer.SetProfile(profile)
     return writer
Exemplo n.º 2
0
    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:'
for i in range(npins):
    pinprop = writer.GetInputProps(i)
    pintype = pinprop.GetType()
    print i, '\t', findguid(pintype)
    if pintype == wmfapi.WMMEDIATYPE_Audio:
        audiopinix = i
        audiopinprops = pinprop
        audiopinmt = pinprop.GetMediaType()
if audiopinix >= 0:
Exemplo n.º 3
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()