我试图用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;
}
丢失的C ++的C版本工作正常:
const auto sample = gst_base_sink_get_last_sample (vsink -> Gst::BaseSink::gobj ());