我正在使用qt示例中的媒体播放器示例,我正在尝试创建自定义视频表面。我希望能够实时操纵帧对它们进行一些操作(例如高斯滤波器)。 我的视频表面代码如下所示:
QList<QVideoFrame::PixelFormat> VideoSurface::supportedPixelFormats(
QAbstractVideoBuffer::HandleType handleType) const
{
Q_UNUSED(handleType);
// Return the formats you will support
return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB565;
}
bool VideoSurface::present(const QVideoFrame &frame)
{
Q_UNUSED(frame);
// Handle the frame and do your processing
return true;
}
我是否需要实现启动功能才能使其工作? 我的播放器代码如下所示:
player = new QMediaPlayer(this);
// owned by PlaylistModel
playlist = new QMediaPlaylist();
player->setPlaylist(playlist);
/*
QVideoRendererControl* rendererControl = player->service()->requestControl<QVideoRendererControl*>();
if (rendererControl)
rendererControl->setSurface(videoSurf);
else
qDebug() << "QtVideoSource: Unable to get QVideoRenderControl for video integration. No video will be emitted from this video source.";
*/
//! [create-objs]
connect(player, SIGNAL(durationChanged(qint64)), SLOT(durationChanged(qint64)));
connect(player, SIGNAL(positionChanged(qint64)), SLOT(positionChanged(qint64)));
connect(player, SIGNAL(metaDataChanged()), SLOT(metaDataChanged()));
connect(playlist, SIGNAL(currentIndexChanged(int)), SLOT(playlistPositionChanged(int)));
connect(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
this, SLOT(statusChanged(QMediaPlayer::MediaStatus)));
connect(player, SIGNAL(bufferStatusChanged(int)), this, SLOT(bufferingProgress(int)));
connect(player, SIGNAL(videoAvailableChanged(bool)), this, SLOT(videoAvailableChanged(bool)));
connect(player, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(displayErrorMessage()));
VideoSurface* videoSurf = new VideoSurface();
//Don't use video Widget, but the custom video surface
videoWidget = new VideoWidget(this);
player->setVideoOutput(videoSurf);
播放器启动,音频像往常一样工作,时间计数器像往常一样,但显示器是黑色的,没有视频。我该怎么做才能看到这些画面?另外,我很想知道QVideoRendererControl的注释部分。我从一些网站得到它并想知道,它是一种替代方法来操纵框架而不是现在的功能或它有什么用? 提前谢谢
答案 0 :(得分:0)
您不想使用QAbstractVideoSurface代替QAbstractVideoBuffer吗? 在这种情况下,您还需要实现isFormatSupported和supportedPixelFormats函数。当然要开始吧。