connect(this->player, &QMediaPlayer::videoFrameChanged, [=]() { QImage image = QImage(this->player-->surfaceFormat().size(), QImage::Format_ARGB32); QPainter painter(&image); this->player->videoSurface()->surfaceFormat().videoFrameToPixmap(this->player->currentVideoFrame()).toImage().scaled(image.size()).swap(image); painter.end(); ui->pictrue_lab->setPixmap(QPixmap::fromImage(image)); });error: 'videoFrameChanged' is not a member of 'QMediaPlayer' connect(this->player, &QMediaPlayer::videoFrameChanged, [=]() {
时间: 2023-06-25 20:06:13 浏览: 164
看起来这个错误是因为 QMediaPlayer 没有名为 videoFrameChanged 的成员。我猜测你可能想要使用 QAbstractVideoSurface::videoFrameChanged 信号,这是在视频帧更改时发出的信号。你需要创建一个自定义的 QAbstractVideoSurface 子类,并将其设置为 QMediaPlayer 的视频输出面。然后,你可以连接 QAbstractVideoSurface::videoFrameChanged 信号到一个槽函数,该函数会在视频帧更改时被调用,从而更新显示的图像。以下是一个基本的示例:
```
class VideoSurface : public QAbstractVideoSurface {
Q_OBJECT
public:
VideoSurface(QObject *parent = nullptr) : QAbstractVideoSurface(parent) {}
QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const override {
Q_UNUSED(handleType);
return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_ARGB32;
}
bool present(const QVideoFrame &frame) override {
if (frame.isValid()) {
QImage image(frame.bits(), frame.width(), frame.height(), frame.bytesPerLine(), QVideoFrame::imageFormatFromPixelFormat(frame.pixelFormat()));
emit videoFrameChanged(image);
return true;
}
return false;
}
signals:
void videoFrameChanged(const QImage &image);
};
```
然后在你的代码中使用该类:
```
VideoSurface *surface = new VideoSurface(this);
player->setVideoOutput(surface);
connect(surface, &VideoSurface::videoFrameChanged, [=](const QImage &image) {
ui->pictrue_lab->setPixmap(QPixmap::fromImage(image));
});
```
这样每当视频帧更改时,就会发出 VideoSurface::videoFrameChanged 信号,并将新图像传递给槽函数来更新 QLabel 中的图像。
阅读全文