0

我从 QAbstractVideo Surface 重新实现了本方法,以便从 IP 摄像机捕获帧。

这是我重新实现的方法(必需的):

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

这就是我使用它的方式:

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();

问题是创建的图像为空。据我所知,这只能是因为框架有效但不包含数据。

任何想法可能是什么问题?

重要细节:如果我将流设置为 QVideoWidget 并简单地显示它,它就可以正常工作。

4

1 回答 1

0

所以我发现了问题所在。

这个:

QVideoFrame::imageFormatFromPixelFormat(cloneFrame .pixelFormat())

返回无效格式,因为 IP cam 将格式提供为 QImage 无法处理的 YUV 格式。解决方案是强制格式化,我发现唯一没有使程序崩溃的是:QImage::Format_Grayscale8。

就这样,它奏效了。

于 2016-07-12T12:36:06.280 回答