我正在使用QtGStreamer 0.10.0,我试图检索视频大小,但它返回的是高度、和宽度值的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在网络上找到一个相关的例子。
发布于 2011-11-11 17:00:24
解决了这个问题,。在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>();
// ...
}https://stackoverflow.com/questions/8084849
复制相似问题