Last active
June 22, 2021 19:15
-
-
Save JC3/a7bab65acbd7659d1e57103d2b0021ba to your computer and use it in GitHub Desktop.
VideoProbeSurface for when your QVideoProbe isn't working.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef VIDEOPROBESURFACE_H | |
#define VIDEOPROBESURFACE_H | |
#include <QAbstractVideoSurface> | |
#include <QVideoSurfaceFormat> | |
/* A bit of a hack, but... | |
* | |
* Example: | |
* | |
* QMediaPlayer *player = ...; | |
* | |
* QVideoWidget *widget = ...; | |
* | |
* VideoProbeSurface *probe = new VideoProbeSurface(...); | |
* probe->setFormatSource(widget->videoSurface()); | |
* connect(probe, &VideoProbeSurface::videoFrameProbed, ...); | |
* | |
* player->setVideoOutput({ widget->videoSurface(), probe }); | |
*/ | |
class VideoProbeSurface : public QAbstractVideoSurface { | |
Q_OBJECT | |
public: | |
VideoProbeSurface (QObject *parent = nullptr) | |
: QAbstractVideoSurface(parent) | |
, formatSource_(nullptr) | |
{ | |
} | |
void setFormatSource (QAbstractVideoSurface *source) { | |
formatSource_ = source; | |
} | |
QList<QVideoFrame::PixelFormat> supportedPixelFormats (QAbstractVideoBuffer::HandleType type) const override { | |
return formatSource_ ? formatSource_->supportedPixelFormats(type) | |
: QList<QVideoFrame::PixelFormat>(); | |
} | |
QVideoSurfaceFormat nearestFormat (const QVideoSurfaceFormat &format) const override { | |
return formatSource_ ? formatSource_->nearestFormat(format) | |
: QAbstractVideoSurface::nearestFormat(format); | |
} | |
bool present (const QVideoFrame &frame) override { | |
emit videoFrameProbed(frame); | |
return true; | |
} | |
signals: | |
void videoFrameProbed (const QVideoFrame &frame); | |
private: | |
QAbstractVideoSurface *formatSource_; | |
}; | |
#endif // VIDEOPROBESURFACE_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related posts:
QImage
example)