2015-10-05 145 views
1

我正在使用qt示例中的媒体播放器示例,并试图创建自定义视频表面。我希望能够实时操纵这些帧来对它们进行一些操作(例如高斯滤波器)。 我的视频面的代码如下所示:如何在qtcreator中实现Qabstractvideosurface并监视每帧视频?

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

您是不是想要使用QAbstractVideoSurface而不是QAbstractVideoBuffer? 在这种情况下,您还需要实现isFormatSupported和supportedPixelFormats函数。当然,开始吧。

+0

你的意思是写'supportedPixelFormats(QAbstractVideoSurface handleType)const'吗?如果我这样做,我得到一个无法声明参数'handleType'为抽象类型'QAbstractVideoSurface' QAbstractVideoSurface handleType)const; 错误。你的意思是开始实施启动功能吗?我使用了[link](http://code.google.com/p/dviz/source/browse/trunk/src/glvidtex/QtVideoSource.cpp)的片段,但是我的视频采用了yuv420p格式,我无法转换它为qimage。我真的需要isFormatSupported吗?目前的功能被重复调用,我测试了一个打印命令。 – Rareform