gtk - Gtk/Gstreamer 应用程序在第一帧冻结
问题描述
我正在尝试制作一个通过 gtk 绘图区域流式传输视频的应用程序。我目前正在尝试运行的管道是 videotestsrc !ximagesink。我的问题是,当我尝试运行我的程序时,它显示 videotestsrc,但仅显示为静止图像。这与通过终端运行“gst-launch-1.0 videotestsrc!ximagesink”不同,右下角的静态移动。
关于我做错了什么的任何想法?
int main(int argc, char* argv[])
{
Gst::init(argc, argv);
auto app = Gtk::Application::create(argc, argv, "gtkmm.video.sunshine.test");
Program_Window window;
return app->run(window);
}
class Program_Window : public Gtk::Window
{
public:
Program_Window();
virtual ~Program_Window();
protected:
Gtk::DrawingArea* display;
Glib::RefPtr<Gst::Pipeline> playbin;
gulong window_handler;
GstVideoOverlay* overlay;
void on_display_realize();
};
Program_Window::Program_Window()
{
//initialize variables
display = new Gtk::DrawingArea();
window_handler = 0;
//connect realize callback
display->signal_realize().connect( sigc::mem_fun( *this, &Program_Window::on_display_realize ));
//create playbin
playbin = Gst::PlayBin::create("playbin");
//prepare elements for the pipeline
Glib::RefPtr<Gst::Element> source = Gst::ElementFactory::create_element("videotestsrc", "src");
Glib::RefPtr<Gst::Element> sink = Gst::ElementFactory::create_element("ximagesink", "sink");
//add elements to the pipeline
playbin->add(source)->add(sink);
//link elements
source->link(sink);
//prep video overlay interface
overlay = (GstVideoOverlay*) sink->gobj();
//add drawing area to main window
add(*display);
show_all_children();
}
void Program_Window::on_display_realize()
{
//acquire an xwindow pointer to our draw area
window_handler = GDK_WINDOW_XID( display->get_window()->gobj() );
//give xwindow pointer to our pipeline via video overlay interface
gst_video_overlay_set_window_handle(overlay, window_handler);
//start video
playbin->set_state(Gst::STATE_PLAYING);
}
解决方案
解决它。无论出于何种原因,该程序不喜欢我使用 playbin 的方式。将其更改为正常的 Gst::pipeline 有效。
//create playbin //in the above code
//playbin = Gst::PlayBin::create("playbin"); //change this
playbin = Gst::Pipeline::create("pipeline"); //to this
推荐阅读
- java - 我们可以在 C++ 资源中嵌入可执行 jar 文件并从内存中运行它吗?
- python - 在 groupby 之后对每个组进行相当复杂的计算
- apache-spark - Databricks 中的花拼花数据集在哪里
- python - 无法保存对 BytesIO 缓冲区的更改
- swift - 如何在执行新动画时保持初始动画运行?
- c++ - 无法在 C++ 中读取 .cpp 文件
- php - 尝试运行 composer install 时出错:“使用未定义的常量 SeP”
- php - 状态 404:ZF3 和 Nginx
- c# - 无法安装 discord.net - 无法从远程源检索有关“Discord.Net.Core”的信息
- java - Spring Boot 资源服务器主体名称