How to output GStreamer video to Gdk.Pixbuf using Vala?

倖福魔咒の 提交于 2019-12-12 04:53:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!