【发布时间】:2017-10-02 14:09:54
【问题描述】:
我正在尝试使用以下代码在 QLabel 中显示视频帧,但不幸的是,视频未显示在 QLabel 上。我已将 QAbstractVideoSurface 继承到 CameraFrameGrabber。
bool CameraFrameGrabber::present(const QVideoFrame &frame)
{
qDebug() << __FUNCTION__;
if (frame.isValid()) {
QVideoFrame cloneFrame(frame);
cloneFrame.map(QAbstractVideoBuffer::ReadOnly);
const QImage image(cloneFrame.bits(),
cloneFrame.width(),
cloneFrame.height(),
QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat()));
if (MainWindow* child = dynamic_cast<MainWindow*>(this)) {
//QGraphicsScene *scene = new QGraphicsScene(this);
//scene->addPixmap(QPixmap::fromImage(image));
//scene->setSceneRect(image.rect());
child->ui->label->setPixmap(QPixmap::fromImage(image));
child->ui->label->update();
//child->ui->graphicsView->setScene(scene);
//child->ui->graphicsView->update();
}
//emit frameAvailable(image);
cloneFrame.unmap();
return true;
}
return false;
}
【问题讨论】:
-
你有没有试过调试看看图片是否包含真实数据?
-
我发现问题出在 QVideoFrame 的格式上,它无法在 QLabel 中显示。有什么建议吗?
标签: qt video-streaming qlabel qpixmap