1

我正在使用 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 的评论部分。我从某个站点得到它并想知道,它是操纵框架而不是当前功能的替代方法还是有什么好处?先感谢您

4

1 回答 1

0

您不是要使用 QAbstractVideoSurface 而不是 QAbstractVideoBuffer 吗?在这种情况下,您还需要实现 isFormatSupported 和 supportedPixelFormats 函数。当然启动它。

于 2015-10-05T16:05:18.197 回答