2014-11-24 28 views
0

我在我的程序中使用GStreamer 1.0從文件播放視頻。我想輸出到Gdk.Pixbuf將其添加到圖像來顯示它。但我無法弄清楚如何正確使用它。如何使用Vala將GStreamer視頻輸出到Gdk.Pixbuf?

這裏是我試圖這樣做,但它不會編譯:

this.pipeline = new Pipeline ("mypipeline"); 
this.src = ElementFactory.make ("filesrc", "video"); 
src.set("location", downloadFileName); 
this.sink = ElementFactory.make ("gdkpixbufsink", "sink"); 
this.pipeline.add_many (this.src, this.sink); 
this.src.link (this.sink); 

this.pipeline.set_state (State.PLAYING); 

this.videoPixbuf = sink.get("last-pixbuf") as Gdk.Pixbuf; 

你建議我怎麼做正確,如果可能的話?或者我怎樣才能做到這一點,而不使用Gdk.Pixbuf?我只是不知道該怎麼做。

回答

3

編輯:馬修·沃特斯提供基於GTK/GST元素爲您提供:https://github.com/ystreet/gtkgst

「gtksink」 元素爲你的應用提供視頻窗件

public static void main (string[] args) { 
    X.init_threads(); 
    Gst.init (ref args); 
    Gtk.init (ref args); 

    var sink = Gst.ElementFactory.make ("gtksink", "sink"); 
    var playbin = Gst.ElementFactory.make ("playbin", "bin"); 
    playbin["video-sink"] = sink; 
    playbin["uri"] = "http://www.nicolas-hoffmann.net/animations/Cavernae_Terragen2.mp4"; 
    Gtk.Widget area; 
    sink.get ("widget", out area); 
    var win = new Gtk.Window(); 
    var bar = new Gtk.HeaderBar(); 
    bar.title = "Test"; 
    bar.show_close_button = true; 
    win.set_titlebar (bar); 
    win.add (area); 
    win.realize.connect (() => { 
      playbin.set_state (Gst.State.PLAYING); 
    }); 
    win.set_size_request (400, 300); 
    win.show_all(); 
    Gtk.main(); 
} 
相關問題