问题
I am using GStreamer 1.0 in my program to play video from file. And I want to output it to Gdk.Pixbuf to add it to Image to display it. But I can't figure out how to use it properly.
Here is what I tried to do, but it won't compile:
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;
Can you suggest me how to do it properly, if possible? Or how I can do it the other way, without using Gdk.Pixbuf? I just don't know what to do.
回答1:
I don't know about vala but you should have a look there:
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gst-plugins-base-libs-gstvideooverlay.html, look for the C Gtk implementation of videooverlay usage, this should be easily translatable to Vala.
回答2:
Edit: Matthew Waters provide Gtk/Gst elements for you : https://github.com/ystreet/gtkgst
gtksink
element provide a video widget for your app
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();
}
来源:https://stackoverflow.com/questions/27111835/how-to-output-gstreamer-video-to-gdk-pixbuf-using-vala