gstreamermm:如何提取Gst :: PlayBin的最后一个视频帧

时间:2016-03-11 09:44:48

标签: c++ c gstreamer

我尝试使用gstreamermm 1.0提取视频的最后一帧,然后使用示例https://github.com/GNOME/gstreamermm/blob/master/examples/media_player_gtkmm/player_window.cc进行处理,但我只得到白色像素。

如何将流的最后一个视频帧提取为原始rgba或bgra数据?

void
MediaStream::setup ()
{
    player = Gst::PlayBin::create ("player");
    vsink  = Gst::XImageSink::create ("vsink");

    player -> set_property ("video-sink", vsink);
    player -> signal_video_changed () .connect (sigc::mem_fun (*this, &MediaStream::on_video_changed));
}


void
MediaStream::on_video_changed ()
{
    Glib::RefPtr <Gst::Pad> pad = player -> get_video_pad (0);

    if (pad)
        pad -> add_probe (Gst::PAD_PROBE_TYPE_BUFFER, sigc::mem_fun (*this, &MediaStream::on_video_pad_got_buffer));
}

Gst::PadProbeReturn
MediaStream::on_video_pad_got_buffer (const Glib::RefPtr <Gst::Pad> & pad, const Gst::PadProbeInfo & data)
{
    const auto width  = vsink -> get_width ();
    const auto height = vsink -> get_height ();


    std::vector <uint8_t> image (width * height * 4);


    // Got no data
    data .get_buffer () -> extract (0, image .data (), image .size ());



    return Gst::PAD_PROBE_OK;
}

1 个答案:

答案 0 :(得分:0)

错过C ++的C版工作正常:

const auto sample = gst_base_sink_get_last_sample (vsink -> Gst::BaseSink::gobj ());