You can subclass QAbstractVideoSurface and get the image data from the incoming QVideoFrame object in present method:
class MyVideoSurface: public QAbstractVideoSurface{
Q_OBJECT
public:
MyVideoSurface
(QObject * parent
=NULL) : QAbstractVideoSurface
(parent
) {}
QList<QVideoFrame::PixelFormat>
supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const{
...
return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB24 << ...; // here return whatever formats you will handle
}
bool present(const QVideoFrame& frame){
if (frame.isValid() && ...) {
QVideoFrame cloneFrame(frame);
cloneFrame.map(QAbstractVideoBuffer::ReadOnly);
const QImage img
(cloneFrame.
bits(),
cloneFrame.width(),
cloneFrame.height(),
QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat()));
// do something with the image ...
cloneFrame.unmap();
return true;
}
return false;
}
};
class MyVideoSurface: public QAbstractVideoSurface{
Q_OBJECT
public:
MyVideoSurface(QObject * parent=NULL) : QAbstractVideoSurface(parent)
{}
QList<QVideoFrame::PixelFormat>
supportedPixelFormats(QAbstractVideoBuffer::HandleType type) const{
...
return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_RGB24 << ...; // here return whatever formats you will handle
}
bool present(const QVideoFrame& frame){
if (frame.isValid() && ...) {
QVideoFrame cloneFrame(frame);
cloneFrame.map(QAbstractVideoBuffer::ReadOnly);
const QImage img(cloneFrame.bits(),
cloneFrame.width(),
cloneFrame.height(),
QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat()));
// do something with the image ...
cloneFrame.unmap();
return true;
}
return false;
}
};
To copy to clipboard, switch view to plain text mode
Of course this way you cannot use QVideoWidget as the QCamera object can have only one viewfinder attached - so you'll have to handle the rendering yourself.
Bookmarks