Exemplo n.º 1
0
    def redirectAudioFilter(self, fg, hint=None):
        # find renderer
        try:
            aurenderer = fg.FindFilterByName('Default DirectSound Device')
        except:
            aurenderer=None
        if not aurenderer:
            try:
                aurenderer=fg.FindFilterByName('Default WaveOut Device')
            except:
                aurenderer=None
        if not aurenderer and hint:
            try:
                aurenderer=fg.FindFilterByName(hint)
            except:
                aurenderer=None
        if not aurenderer:
            print 'Audio renderer not found'
            return None

        enumpins=aurenderer.EnumPins()
        pin=enumpins.Next()
        try:
            aulastpin=pin.ConnectedTo()
            fg.RemoveFilter(aurenderer)
        except:
            return None
        try:
            f = dshow.CreateFilter('Audio Pipe')
        except:
            print 'Audio pipe filter is not installed'
            return None

        try:
            wmconv=f.QueryIPipe()
        except:
            print 'Filter does not support interface IPipe'
            return
        wmconv.SetAdviceSink(self._audiopeer)

        fg.AddFilter(f,'AWMC')

        fg.Render(aulastpin)

        return fg
Exemplo n.º 2
0
    def __createFilterGraph(self, url):
        fg = dshow.CreateGraphBuilder()
        url = MMurl.canonURL(url)
        url = MMurl.unquote(url)
        try:
            fg.RenderFile(url)
        except:
            return None
        # find renderer
        try:
            aurenderer=fg.FindFilterByName('Default DirectSound Device')
        except:
            aurenderer=None
        if not aurenderer:
            try:
                aurenderer=fg.FindFilterByName('Default WaveOut Device')
            except:
                aurenderer=None
        if not aurenderer:
            print 'Audio renderer not found'
            return None

        enumpins=aurenderer.EnumPins()
        pin=enumpins.Next()
        aulastpin=pin.ConnectedTo()
        fg.RemoveFilter(aurenderer)
        try:
            f = dshow.CreateFilter('Audio Pipe')
        except:
            print 'Audio pipe filter is not installed'
            return None

        try:
            wmconv=f.QueryIPipe()
        except:
            print 'Filter does not support interface IPipe'
            return
        wmconv.SetAdviceSink(self._audiopeer)

        fg.AddFilter(f,'AWMC')

        fg.Render(aulastpin)

        return fg
Exemplo n.º 3
0
    def createFilterGraph(self, url):
        fg = dshow.CreateGraphBuilder()
        import MMurl
        url = MMurl.canonURL(url)
        url = MMurl.unquote(url)
        fg.RenderFile(url)

        # find video renderer filter and remove it
        renderer = fg.FindFilterByName('Video Renderer')
        enumpins = renderer.EnumPins()
        pin = enumpins.Next()
        lastpin = pin.ConnectedTo()
        fg.RemoveFilter(renderer)

        # create wmv converter filter
        try:
            vf = dshow.CreateFilter('Video Windows Media Converter')
        except:
            print 'Video windows media converter filter is not installed'
            return None

        # set listener
        try:
            wmconv = vf.QueryIWMConverter()
        except:
            print 'Filter does not support interface IWMConverter'
            return None
        wmconv.SetAdviceSink(self._videopeer)

        # add and connect wmv converter filter
        fg.AddFilter(vf, 'VWMC')
        enumpins = vf.EnumPins()
        pin = enumpins.Next()
        fg.Connect(lastpin, pin)

        # find audio renderer
        try:
            aurenderer = fg.FindFilterByName('Default DirectSound Device')
        except:
            aurenderer = None
        if not aurenderer:
            try:
                aurenderer = fg.FindFilterByName('Default WaveOut Device')
            except:
                aurenderer = None
        if aurenderer:
            enumpins = aurenderer.EnumPins()
            pin = enumpins.Next()
            aulastpin = pin.ConnectedTo()
            fg.RemoveFilter(aurenderer)
            try:
                f = dshow.CreateFilter('Audio Windows Media Converter')
            except:
                print 'Audio windows media converter filter is not installed'
                return None

            try:
                wmconv = f.QueryIWMConverter()
            except:
                print 'Filter does not support interface IWMConverter'
                return
            wmconv.SetAdviceSink(self._audiopeer)

            fg.AddFilter(f, 'AWMC')

            fg.Render(aulastpin)

        return fg
Exemplo n.º 4
0
def convertvideofile(url, dstdir, file, node):
    import producer
    global engine
    # ignore suggested extension and make our own
    file = os.path.splitext(file)[0] + '.rm'
    fullpath = os.path.join(dstdir, file)
    if engine is None:
        engine = producer.CreateRMBuildEngine()
    for pin in engine.GetPins():
        if pin.GetOutputMimeType() == producer.MIME_REALVIDEO:
            videopin = pin
        elif pin.GetOutputMimeType() == producer.MIME_REALAUDIO:
            audiopin = pin
    engine.SetDoOutputMimeType(producer.MIME_REALAUDIO, 0)
    engine.SetDoOutputMimeType(producer.MIME_REALVIDEO, 1)
    engine.SetDoOutputMimeType(producer.MIME_REALEVENT, 0)
    engine.SetDoOutputMimeType(producer.MIME_REALIMAGEMAP, 0)
    engine.SetDoOutputMimeType(producer.MIME_REALPIX, 0)
    engine.SetRealTimeEncoding(0)
    engine.SetDoMultiRateEncoding(1)
    cp = engine.GetClipProperties()
    ts = engine.GetTargetSettings()
    if node is not None:
        cp.SetTitle(MMAttrdefs.getattr(node, 'title'))
        cp.SetAuthor(MMAttrdefs.getattr(node, 'author'))
        cp.SetCopyright(MMAttrdefs.getattr(node, 'copyright'))
        ts.SetVideoQuality(MMAttrdefs.getattr(node, 'project_videotype'))
        ts.RemoveAllTargetAudiences()
        target = MMAttrdefs.getattr(node, 'project_targets')
        for i in range(5):
            if (1 << i) & target:
                ts.AddTargetAudience(i)
        if not target:
            ts.AddTargetAudience(producer.ENC_TARGET_28_MODEM)
    else:
        # we don't know nothin' about the node so use some defaults
        cp.SetTitle('')
        cp.SetAuthor('')
        cp.SetCopyright('')
        # XXX: for testing incr caps
        #ts.AddTargetAudience(producer.ENC_TARGET_28_MODEM)
        ts.AddTargetAudience(producer.ENC_TARGET_DUAL_ISDN)
        #ts.SetVideoQuality(producer.ENC_VIDEO_QUALITY_NORMAL)
        ts.SetVideoQuality(producer.ENC_VIDEO_QUALITY_SMOOTH_MOTION)
    cp.SetPerfectPlay(1)
    cp.SetMobilePlay(0)
    cp.SetSelectiveRecord(0)
    cp.SetDoOutputServer(0)
    cp.SetDoOutputFile(1)
    cp.SetOutputFilename(fullpath)

    import dshow, MMurl
    b = dshow.CreateGraphBuilder()
    url = MMurl.canonURL(url)
    url = MMurl.unquote(url)
    b.RenderFile(url)
    renderer = b.FindFilterByName('Video Renderer')
    enumpins = renderer.EnumPins()
    pin = enumpins.Next()
    lastpin = pin.ConnectedTo()
    b.RemoveFilter(renderer)
    try:
        vf = dshow.CreateFilter('Video Real Media Converter')
    except:
        print 'Video real media converter filter is not installed'
        return
    b.AddFilter(vf, 'VRMC')
    b.Render(lastpin)

    try:
        aurenderer = b.FindFilterByName('Default DirectSound Device')
    except:
        aurenderer = None
    if not aurenderer:
        try:
            aurenderer = b.FindFilterByName('Default WaveOut Device')
        except:
            aurenderer = None
    if aurenderer:
        enumpins = aurenderer.EnumPins()
        pin = enumpins.Next()
        lastpin = pin.ConnectedTo()
        b.RemoveFilter(aurenderer)
        try:
            af = dshow.CreateFilter('Audio Real Media Converter')
        except:
            aurenderer = None
        else:
            b.AddFilter(af, 'ARMC')
            b.Render(lastpin)

    try:
        vrconv = vf.QueryIRealConverter()
    except:
        print 'Filter does not support interface IRealConverter'
        return
    try:
        ukeng = engine.QueryInterfaceUnknown()
    except:
        print 'RMABuildEngine QueryInterfaceUnknown failed'
        return
    vrconv.SetInterface(ukeng, 'IRMABuildEngine')

    try:
        ukpin = videopin.QueryInterfaceUnknown()
    except:
        print 'RMAInputPin QueryInterfaceUnknown failed'
        return
    vrconv.SetInterface(ukpin, 'IRMAInputPin')

    if aurenderer:
        try:
            arconv = af.QueryIRealConverter()
        except:
            aurenderer = None
        else:
            arconv.SetInterface(ukeng, 'IRMABuildEngine')

    if aurenderer:
        try:
            ukpin = audiopin.QueryInterfaceUnknown()
        except:
            aurenderer = None
        else:
            arconv.SetInterface(ukpin, 'IRMAInputPin')

    if aurenderer:
        engine.SetDoOutputMimeType(producer.MIME_REALAUDIO, 1)
        ts.SetAudioContent(producer.ENC_AUDIO_CONTENT_VOICE)

    # PinProperties,MediaSample,PrepareToEncode,Encode, DoneEncoding
    # are all managed by our dshow filter
    mc = b.QueryIMediaControl()
    mc.Run()
    import sys
    if sys.platform == 'win32':
        # remove messages in queue
        # dispatch only paint message
        import win32ui
        while b.WaitForCompletion(0) == 0:
            win32ui.PumpWaitingMessages()
        mc.Stop()
        win32ui.PumpWaitingMessages()
    else:
        b.WaitForCompletion()
        mc.Stop()
    del b
Exemplo n.º 5
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()