0

I'm reimplemented the present method from a QAbstractVideo Surface in order to capture frames from an IP camera.

This is my reimplemented methods (the required ones):

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;
}

And this is is how I used it:

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

QMediaPlayer *a = new QMediaPlayer(this);
QString url = "http://Admin:1234@10.255.255.67:8008";
a->setMedia(QUrl(url));
a->setVideoOutput(grabber);
a->play();

The problem is that the image that is created is null. As far as I can tell, this can only be because the frame is valid but does not contain data.

Any ideas what the problem could be?

Important Detail: If I set the stream to a QVideoWidget and simply show that, it works just fine.

aarelovich
  • 5,140
  • 11
  • 55
  • 106

1 Answers1

0

So I found out what the problem was.

This:

QVideoFrame::imageFormatFromPixelFormat(cloneFrame .pixelFormat())

Was returning invalid format because the IP cam gave the format as a YUV format which QImage can't handle. The solution was to force the format and the only one I found that did not make the program crash was: QImage::Format_Grayscale8.

With that, it worked.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
aarelovich
  • 5,140
  • 11
  • 55
  • 106