2011-11-10 45 views
3

我玩QtGStreamer 0.10.0,我試圖檢索視頻的大小,但它的返回ZERO高度寬度值。檢索視頻大小返回零

但是,我可以播放視頻沒有問題的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 ... 

上面的代碼顯示了管道設置的開始。通過在信號"pad-added"上連接我的方法MyMultimedia::onNewDecodedPad,我可以訪問視頻的數據。至少這是我的想法。

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的Web上找到相關示例。

+0

這看起來類似於gstreamer c例子。你可以看看那些,也許你會發現 –

回答

3

解決了它。在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>(); 

    // ... 
}