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的評論部分。我從一些網站得到它,並想知道,它是一種替代方法來操作框架而不是現在的功能,或者它有什麼好處? 預先感謝您
你的意思是寫'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