将 Gstreamermm 添加到 gtkmm c++

问题描述 投票:0回答:0

目前尝试调整 gtkmm 和 gstreamermm 测试代码将运行时错误 抛给视频而不是声音,我的程序说 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);
  }
terminate called after throwing an instance of 'std::runtime_error'what():  failed to link: source->output

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

c++ linux gstreamer gtkmm
© www.soinside.com 2019 - 2024. All rights reserved.