2016-07-12 8 views
0

Ich habe die vorliegende Methode von einer QAbstractVideo Surface neu implementiert, um Frames von einer IP-Kamera zu erfassen.QAbstractVideoSurface Generating A Null Image

Das ist meine reimplementiert Methode (die erforderlich ist):

QList<QVideoFrame::PixelFormat> CameraFrameGrabber::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const 
{ 
    Q_UNUSED(handleType); 
    return QList<QVideoFrame::PixelFormat>() 
     << QVideoFrame::Format_ARGB32 
     << QVideoFrame::Format_ARGB32_Premultiplied 
     << QVideoFrame::Format_RGB32 
     << QVideoFrame::Format_RGB24 
     << QVideoFrame::Format_RGB565 
     << QVideoFrame::Format_RGB555 
     << QVideoFrame::Format_ARGB8565_Premultiplied 
     << QVideoFrame::Format_BGRA32 
     << QVideoFrame::Format_BGRA32_Premultiplied 
     << QVideoFrame::Format_BGR32 
     << QVideoFrame::Format_BGR24 
     << QVideoFrame::Format_BGR565 
     << QVideoFrame::Format_BGR555 
     << QVideoFrame::Format_BGRA5658_Premultiplied 
     << QVideoFrame::Format_AYUV444 
     << QVideoFrame::Format_AYUV444_Premultiplied 
     << QVideoFrame::Format_YUV444 
     << QVideoFrame::Format_YUV420P 
     << QVideoFrame::Format_YV12 
     << QVideoFrame::Format_UYVY 
     << QVideoFrame::Format_YUYV 
     << QVideoFrame::Format_NV12 
     << QVideoFrame::Format_NV21 
     << QVideoFrame::Format_IMC1 
     << QVideoFrame::Format_IMC2 
     << QVideoFrame::Format_IMC3 
     << QVideoFrame::Format_IMC4 
     << QVideoFrame::Format_Y8 
     << QVideoFrame::Format_Y16 
     << QVideoFrame::Format_Jpeg 
     << QVideoFrame::Format_CameraRaw 
     << QVideoFrame::Format_AdobeDng; 
} 

bool CameraFrameGrabber::present(const QVideoFrame &frame) 
{  
    //qWarning() << "A frame"; 
    if (frame.isValid()) { 
     //qWarning() << "Valid Frame"; 
     QVideoFrame cloneFrame(frame); 
     cloneFrame.map(QAbstractVideoBuffer::ReadOnly); 
     const QImage image(cloneFrame.bits(), 
          cloneFrame.width(), 
          cloneFrame.height(), 
          QVideoFrame::imageFormatFromPixelFormat(cloneFrame .pixelFormat())); 

     qWarning() << "Is created image NULL?" << image.isNull(); 

     if (!image.isNull()) 
      emit nextFrameAsImage(image); 

     cloneFrame.unmap(); 
     return true; 
    } 
    return false; 
} 

Und das ist, wie ich es benutzt:

grabber = new CameraFrameGrabber(this); 
connect(grabber,&CameraFrameGrabber::nextFrameAsImage,this,&QCmaraTest::on_newFrame); 

QMediaPlayer *a = new QMediaPlayer(this); 
QString url = "http://Admin:[email protected]:8008"; 
a->setMedia(QUrl(url)); 
a->setVideoOutput(grabber); 
a->play(); 

Das Problem ist, dass das Bild, das erstellt wird, null ist. Soweit ich das beurteilen kann, kann dies nur daran liegen, dass der Rahmen gültig ist, aber keine Daten enthält.

Irgendwelche Ideen, was das Problem sein könnte?

Wichtiges Detail: Wenn ich den Stream auf ein QVideoWidget setze und das einfach zeige, funktioniert es gut.

Antwort

0

Also habe ich herausgefunden, was das Problem war.

Dieses: QVideoFrame :: imageFormatFromPixelFormat (cloneFrame .pixelFormat())

War Rückkehr ungültigen Format, weil die IP-Cam nicht umgehen kann das Format als YUV-Format, das QImage gab. Die Lösung war, das Format zu erzwingen und das einzige, das ich fand, das das Programm zum Absturz brachte, war: QImage :: Format_Grayscale8.

Damit hat es funktioniert.

Verwandte Themen