Skip to content

Instantly share code, notes, and snippets.

@JC3
Last active Jun 22, 2021
Embed
What would you like to do?
VideoProbeSurface for when your QVideoProbe isn't working.
#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
@JC3

This comment has been minimized.

Copy link
Owner Author

@JC3 JC3 commented Jun 22, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment