首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用QtGStreamer检索视频大小返回零

使用QtGStreamer检索视频大小返回零
EN

Stack Overflow用户
提问于 2011-11-10 18:58:56
回答 1查看 1.1K关注 0票数 3

我正在使用QtGStreamer 0.10.0,我试图检索视频大小,但它返回的是高度、宽度值的0

但是,我可以在QImage上播放视频,没有问题。

代码语言:javascript
复制
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"上,我可以访问视频的数据。至少我是这么想的。

代码语言:javascript
复制
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在网络上找到一个相关的例子。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-11 17:00:24

解决了这个问题,。在onNewDecodedPad(),您仍然无法访问有关视频帧的信息。

MyMultimedia继承自QGst::Utils::ApplicationSink,因此我必须实现一个名为QGst::FlowReturn MyMultimedia::newBuffer()的方法,该方法在新框架准备就绪时由QtGstreamer调用。

换句话说,使用此方法将视频帧复制到QImage。我不知道的是,pullBuffer()返回一个QGst::BufferPtr,其中有一个QGst::CapsPtr。它是这个var的内部结构,它保存了我正在寻找的信息:

代码语言:javascript
复制
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>();

    // ...
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8084849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档