我正在玩 QtGStreamer 0.10.0 并且我正在尝试检索视频大小,但它为高度 和宽度 值返回零。
但是,我可以在 QImage 上毫无问题地播放视频。
QGst::init();
pipeline = QGst::Pipeline::create();
filesrc = QGst::ElementFactory::make("filesrc");
filesrc->setProperty("location", "sample.avi");
pipeline->add(filesrc);
decodebin = QGst::ElementFactory::make("decodebin2").dynamicCast<QGst::Bin>();
pipeline->add(decodebin);
QGlib::connect(decodebin, "pad-added", this, &MyMultimedia::onNewDecodedPad);
QGlib::connect(decodebin, "pad-removed", this, &MyMultimedia::onRemoveDecodedPad);
filesrc->link(decodebin);
// more code ...
上面的代码显示了管道设置的开始。通过将我的方法 MyMultimedia::onNewDecodedPad
连接到信号 “pad-added”
上,我可以访问视频数据。至少我是这么认为的。
void MyMultimedia::onNewDecodedPad(QGst::PadPtr pad)
{
QGst::CapsPtr caps = pad->caps();
QGst::StructurePtr structure = caps->internalStructure(0);
if (structure->name().contains("video/x-raw"))
{
// Trying to print width and height using a couple of different ways,
// but all of them returns 0 for width/height.
qDebug() << "#1 Size: " << structure->value("width").get<int>() << "x" << structure->value("height").get<int>();
qDebug() << "#2 Size: " << structure->value("width").toInt() << "x" << structure->value("height").toInt();
qDebug() << "#3 Size: " << structure.data()->value("width").get<int>() << "x" << structure.data()->value("height").get<int>();
// numberOfFields also returns 0, which is very wierd.
qDebug() << "numberOfFields:" << structure->numberOfFields();
}
// some other code
}
我想知道我可能做错了什么。有小费吗?我无法在网上找到使用此 API 的相关示例。
最佳答案
解决了。在 onNewDecodedPad()
处,您仍然无法访问有关视频帧的信息。
类 MyMultimedia
继承自 QGst::Utils::ApplicationSink
,所以我必须实现一个名为 QGst::FlowReturn MyMultimedia::newBuffer( )
每当新帧准备就绪时由 QtGstreamer 调用。
换句话说,使用此方法将视频的帧复制到QImage
。我不知道的是 pullBuffer()
返回一个 QGst::BufferPtr
,它有一个 QGst::CapsPtr
。这是这个 var 的一个内部结构,它包含我正在寻找的信息:
QGst::FlowReturn MyMultimedia::newBuffer()
{
QGst::BufferPtr buf_ptr = pullBuffer();
QGst::CapsPtr caps_ptr = buf_ptr->caps();
QGst::StructurePtr struct_ptr = caps_ptr->internalStructure(0);
qDebug() << struct_ptr->value("width").get<int>() <<
"x" <<
struct_ptr->value("height").get<int>();
// ...
}
关于c++ - 使用 QtGStreamer 检索视频大小返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8084849/