使用Gstreamer1.0 GTK + 3.0显示视频

时间:2018-04-30 06:17:04

标签: c++ gtk gstreamer

我无法在GtkWidget中正确插入视频。告诉我,我做错了什么?视频将在新窗口中打开,而不是在我发送的视频中。视频应该在后台的那个窗口中打开。

Libvlc库以相同的方式显示,也许问题出现在操作系统中,我在Ubuntu 17.10上写作

App Result Image

#include <iostream>

#include <gtk/gtk.h>

#include <gst/gst.h>
#include <gdk/gdkx.h>

using namespace std;


GstElement *pipeline, *src, *sink, *b;

int main(int argc, char *argv[]) {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!

GtkWidget *window;
 gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  //gtk_container_border_width (GTK_CONTAINER (window), 10);
  GdkColor color;

  gdk_color_parse ("black", &color);

  gtk_widget_modify_bg ( window, GTK_STATE_NORMAL, &color);
  gtk_window_fullscreen((GtkWindow*)window);
  std::string path = std::string("file:///home/stas/eclipse-workspace/TestGTK/0.mp4");


  gst_init (&argc, &argv);




      src = gst_element_factory_make ("videotestsrc", NULL);
      sink = gst_element_factory_make ("gtksink", NULL);
      b = gst_element_factory_make("playbin", "playbin");

      g_object_set(b, "uri", path.c_str());


      gst_bin_add_many (GST_BIN (b), src, sink, NULL);
      gst_element_link (src, sink);

      GtkWidget *area;
      g_object_get (sink, "widget", &area, NULL);
      gtk_container_add (GTK_CONTAINER (window), area);

      gtk_widget_realize(area);

      gtk_widget_show_all (window);
      gst_element_set_state (b, GST_STATE_PLAYING);

      gtk_widget_show (window);

      gtk_main ();
return 0;
}

0 个答案:

没有答案