linux 添加Gstreamermm到gtkmm c++

bkhjykvo  于 2023-08-03  发布在  Linux
关注(0)|答案(1)|浏览(94)

目前尝试将gtkmm and gstreamermm test code throws run time error适配为视频而不是声音,我的程序说m_source和m_sink之间的链接失败。我的理解是,我应该使用playbin的来源和autovideosink。

#include <gtkmm.h>
#include <gstreamermm.h>
#include <glibmm/main.h>
#include <iostream>

class VideoPlayer
{
public:
    VideoPlayer();
    void start_playing(const std::string& filepath);
    bool stop_playing();

private:
    Glib::RefPtr<Gst::Pipeline> m_pipeline;
    Glib::RefPtr<Gst::Element> m_source;
    Glib::RefPtr<Gst::Element> m_sink;
};

VideoPlayer::VideoPlayer()
{
    m_pipeline = Gst::Pipeline::create("video-player");
    m_source = Gst::ElementFactory::create_element("filesrc", "source");
    m_sink = Gst::ElementFactory::create_element("autovideosink", "output");
    m_pipeline->add(m_source);
    m_pipeline->add(m_sink);
    m_source->link(m_sink);
}

void VideoPlayer::start_playing(const std::string& filepath)
{
    m_source->set_property("location", filepath);
    m_pipeline->set_state(Gst::STATE_PLAYING);
}

bool VideoPlayer::stop_playing()
{
    m_pipeline->set_state(Gst::STATE_NULL);
    return false;
}

class HelloWorld : public Gtk::Window
{
public:
    HelloWorld();
    virtual ~HelloWorld();

protected:
    // Signal handlers:
    void on_button_clicked();

    // Member widgets:
    Gtk::Button m_button;
    VideoPlayer m_player;
};

HelloWorld::HelloWorld()
    : m_button("Play Video")
{
    // Sets the border width of the window.
    set_border_width(10);

    // When the button receives the "clicked" signal, it will call the
    // on_button_clicked() method defined below.
    m_button.signal_clicked().connect(sigc::mem_fun(*this, &HelloWorld::on_button_clicked));

    // This packs the button into the Window (a container).
    add(m_button);

    // The final step is to display this newly created widget...
    m_button.show();
}

   HelloWorld::~HelloWorld()
   {
   }

   void HelloWorld::on_button_clicked()
   {
    std::string filepath = "~/Junior_Design/song.mp4";
    m_player.start_playing(filepath);
     std::cout << "Playing video..." << std::endl;
    }

    int main(int argc, char* argv[])
    {
     Gst::init();
     auto app = Gtk::Application::create(argc, argv, "org.gtkmm.example");

      HelloWorld helloworld;

     // Shows the window and returns when it is closed.
      return app->run(helloworld);
  }

个字符
我正在尝试修复此错误代码

b1zrtrql

b1zrtrql1#

一些想法:
1.在src和sink之间可能需要一个videoconvertautovideoconvert
1.使用具有不同文件格式的另一个文件进行测试。
另外,我不认为这会在GTK窗口中实际呈现视频。它可能会打开另一个窗口,但gstreamer将单独执行。

相关问题