我需要关于gstreamer0.10音频“交错”的帮助

2024-10-02 04:22:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我在试着编一个视频/音频配音编辑器。尝试在vala/genie中混合多个音频文件。使用加法器或交织器。在

我需要将这个gst启动命令发送到Genie或Vala代码,但是使用:1。-Gst.Element.link2.-Gst.ElementFactory.make3.-请求和其他。。。请不要使用parse_launch()

gst-launch-0.10 interleave name=i ! audioconvert ! wavenc ! filesink location=file.wav  filesrc location=file1.wav ! decodebin ! audioconvert ! "audio/x-raw-int,channels=1" ! queue ! i.   filesrc location=file2.wav !  decodebin ! audioconvert ! "audio/x-raw-int,channels=1" ! queue ! i.

我有个精灵密码:

^{pr2}$

我不知道出了什么问题。在


Tags: raw视频queuelocation音频launchaudioint
3条回答

多亏了Che Bizarro,我用精灵中的这个简单代码解决了这个问题。在

uses Gst
//adder name=mix ! volume volume=0.1 ! alsasink filesrc location=file1.wav ! wavparse ! audioconvert ! mix. filesrc location=file2.wav ! wavparse ! audioconvert ! mix. filesrc location=file3.wav ! wavparse ! audioconvert !  mix.


class  AudioFilesSrc : Gst.Bin
    wavparse: Element
    src:Element
    audioconvert: Element

    def OnDynamicPad (element:Element, zz:Pad)
        var opad = audioconvert.get_static_pad("sink");
        zz.link(opad);

    def open(s1:string)

        src = Gst.ElementFactory.make("filesrc", "src1");
        wavparse = ElementFactory.make("wavparse","wavparse");
        audioconvert = ElementFactory.make("audioconvert","audioconvert");
        wavparse.pad_added.connect(OnDynamicPad);
        this.add_many(src,wavparse,audioconvert);
        src.link_many(wavparse,audioconvert);
        src.set("location",s1);




class Pipe:GLib.Object
    pipeline:Pipeline
    adder: Element
    sink: Element


    def create()    
        pipeline= new Pipeline("test");
        adder = ElementFactory.make("adder","mixer");
        var volume= ElementFactory.make("volume","volume");
        volume.set("volume",0.1)
        sink= ElementFactory.make("autoaudiosink","alsasink");
        pipeline.add_many(adder,volume,sink)
        adder.link_many(volume,sink)

    def conector(bin:Bin)
        // Add the new Bin to our pipeline.
        pipeline.add(bin)
        // search the audioconvert element and get its src for give it to the Bin.
        var e=bin.get_by_name("audioconvert")
        var srcpad = new Gst.GhostPad("src", e.get_static_pad("src"));
        bin.add_pad(srcpad);
        // create a new sink pad into the adder element
        var ch1_sinkpad = adder.get_request_pad("sink%d")
        // Link sources to mixer
        bin.get_pad("src").link(ch1_sinkpad)

    def play()
        pipeline.set_state(Gst.State.PLAYING);



init
    Gst.init(ref args);
    var pipe= new Pipe()
    pipe.create()

    var archivos= new list of AudioFilesSrc
    for var i=0 to 1
        archivos.add(new AudioFilesSrc())
        archivos[i].open("file"+(i).to_string()+".wav") // you need several filenames with this format file%d.wav : file0.wav, file1.wav....
        pipe.conector(archivos[i])
    pipe.play()

    new MainLoop().run();

在手动构建管道时,需要考虑很多细节,特别是将元素链接在一起时。我建议您使用可用的解析器包装器,这样更方便。看看下面的片段,它的功能与您的完全相同,但在内部处理细节(在我看来更干净)

祝你好运! 格鲁纳

uses Gst

pipeline: private Pipeline 
gst_launch: private string

init
    Gst.init (ref args);

    gst_launch = "interleave name=i ! audioconvert ! wavenc ! filesink location=file.wav filesrc location=file1.wav ! decodebin ! audioconvert ! 'audio/x-raw-int,channels=1' ! queue ! i.   filesrc location=file2.wav ! decodebin ! audioconvert ! 'audio/x-raw-int,channels=1' ! queue ! i."

    pipeline = Gst.parse_launch(gst_launch) as Pipeline;

    pipeline.set_state(Gst.State.PLAYING)

    new MainLoop().run();

只要文件格式相同(.wav或.mp3),下面的Vala代码就可以工作。在

using Gst;

public class AudioFileSource : Gst.Bin {

    string filename;
    Gst.Caps outcaps;
    Gst.Element filesrc;

    Gst.Element dbin; 
    Gst.Element ident;
    Gst.Element audioconvert;
    Gst.Element volume;

    /**
     * AudioFileSource - creates an input source Bin from a filename
     * @param filename: The name of the audio file to load. 
     * @param volume: Volume level (fractional, may go above 1.0)
     * @param outcaps: Optional GStreamer capabilities object. A sensible
        default will be used if not given.
     */ 
    public AudioFileSource (string filename, double volume = 0.5, Gst.Caps? outcaps = null) {

        this.filename = filename;

        if (outcaps == null)
            this.outcaps = Gst.Caps.from_string("audio/x-raw,format=int,channels=2,rate=44100,depth=16");
        else
            this.outcaps = outcaps;

        filesrc = Gst.ElementFactory.make("filesrc", "src");
        filesrc.set("location", this.filename);

        dbin = Gst.ElementFactory.make("decodebin", null);
        ident = Gst.ElementFactory.make("identity", null);
        audioconvert = Gst.ElementFactory.make("audioconvert", null);

        this.volume = Gst.ElementFactory.make("volume", null);
        this.volume.set_property("volume", volume);

        add_many(filesrc, dbin, ident, audioconvert, this.volume);
        filesrc.link(dbin);

        audioconvert.link(this.volume);
        this.volume.link_filtered(ident, outcaps);

        // Create an output from this bin (the "src" of the ident instance
        // becomes the the "src" of this bin)
        var srcpad = new Gst.GhostPad("src", ident.get_static_pad("src"));
        add_pad(srcpad);

        dbin.pad_added.connect((e, p) => {
            p.link(audioconvert.get_static_pad("sink"));
        });
    }
}

public class SimpleMixer : GLib.Object {
    /*
    Simple class that mixes audio sources straight over the top of each other.
    */

    Gst.Pipeline pipeline;
    Gst.Element mixer;
    Gst.Element audioconvert;
    Gst.Element sink;

    AudioFileSource[] sources = {};

    public signal void finished();

    public SimpleMixer () {
        pipeline = new Gst.Pipeline("mypipeline");
        mixer = Gst.ElementFactory.make("adder", null);
    }

    public void stop(Message msg) {
        if (msg.type == Gst.MessageType.EOS) {
            pipeline.set_state(Gst.State.NULL);
            finished();
        }
    }

    public void add_source (string filename) {
        sources += new AudioFileSource(filename);
    }

    public void mix (string output) {

        audioconvert = Gst.ElementFactory.make("wavenc", null);
        sink = Gst.ElementFactory.make("filesink", "sink");
        sink.set("location", output);

        foreach (var source in sources)
            pipeline.add(source);

        pipeline.add(mixer);

        foreach (var source in sources)
            source.get_static_pad("src").link(mixer.get_request_pad("sink_%u"));

        pipeline.add(audioconvert);
        mixer.link(audioconvert);
        pipeline.add(sink);
        audioconvert.link(sink);

        var bus = pipeline.get_bus();
        bus.add_signal_watch(GLib.Priority.HIGH);
        bus.message.connect(stop);

        pipeline.set_state(Gst.State.PLAYING);
    }
}

static int main(string[] args) {
    Gst.init(ref args);
    var mainloop = new MainLoop();

    var mixer = new SimpleMixer();
    for (int i = 2; i < args.length; i++)
        mixer.add_source (args[i]);

    mixer.finished.connect(() => {
        mainloop.quit();
    });

    mixer.mix(args[1]);

    mainloop.run();

    return 0;
}

您应该使用gstreamer-1.0编译它:

^{pr2}$

要使用它:

./mixer totalfinal.wav file1.wav file2.wav

希望这能帮你开始。在

相关问题 更多 >

    热门问题