![]() |
Qt 6.x
The Qt SDK
|
The QVideoFrame class represents a frame of video data. More...
#include <qvideoframe.h>
Classes | |
struct | PaintOptions |
Public Types | |
enum | HandleType { NoHandle , RhiTextureHandle } |
Identifies the type of a video buffers handle. More... | |
enum | MapMode { NotMapped = 0x00 , ReadOnly = 0x01 , WriteOnly = 0x02 , ReadWrite = ReadOnly | WriteOnly } |
Enumerates how a video buffer's data is mapped to system memory. More... | |
enum | RotationAngle { Rotation0 = 0 , Rotation90 = 90 , Rotation180 = 180 , Rotation270 = 270 } |
The angle of the clockwise rotation that should be applied to a video frame before displaying. More... | |
Public Member Functions | |
QVideoFrame () | |
Constructs a null video frame. | |
QVideoFrame (const QVideoFrameFormat &format) | |
Constructs a video frame of the given pixel format. | |
QVideoFrame (const QVideoFrame &other) | |
Constructs a shallow copy of other. | |
~QVideoFrame () | |
Destroys a video frame. | |
QVideoFrame (QVideoFrame &&other) noexcept=default | |
Constructs a QVideoFrame by moving from other. | |
void | swap (QVideoFrame &other) noexcept |
Swaps the current video frame with other. | |
QVideoFrame & | operator= (const QVideoFrame &other) |
Moves other into this QVideoFrame. | |
bool | operator== (const QVideoFrame &other) const |
bool | operator!= (const QVideoFrame &other) const |
bool | isValid () const |
Identifies whether a video frame is valid. | |
QVideoFrameFormat::PixelFormat | pixelFormat () const |
Returns the pixel format of this video frame. | |
QVideoFrameFormat | surfaceFormat () const |
Returns the surface format of this video frame. | |
QVideoFrame::HandleType | handleType () const |
Returns the type of a video frame's handle. | |
QSize | size () const |
Returns the dimensions of a video frame. | |
int | width () const |
Returns the width of a video frame. | |
int | height () const |
Returns the height of a video frame. | |
bool | isMapped () const |
Identifies if a video frame's contents are currently mapped to system memory. | |
bool | isReadable () const |
Identifies if the mapped contents of a video frame were read from the frame when it was mapped. | |
bool | isWritable () const |
Identifies if the mapped contents of a video frame will be persisted when the frame is unmapped. | |
QVideoFrame::MapMode | mapMode () const |
Returns the mode a video frame was mapped to system memory in. | |
bool | map (QVideoFrame::MapMode mode) |
Maps the contents of a video frame to system (CPU addressable) memory. | |
void | unmap () |
Releases the memory mapped by the map() function. | |
int | bytesPerLine (int plane) const |
Returns the number of bytes in a scan line of a plane. | |
uchar * | bits (int plane) |
Returns a pointer to the start of the frame data buffer for a plane. | |
const uchar * | bits (int plane) const |
Returns a pointer to the start of the frame data buffer for a plane. | |
int | mappedBytes (int plane) const |
Returns the number of bytes occupied by plane plane of the mapped frame data. | |
int | planeCount () const |
Returns the number of planes in the video frame. | |
qint64 | startTime () const |
Returns the presentation time (in microseconds) when the frame should be displayed. | |
void | setStartTime (qint64 time) |
Sets the presentation time (in microseconds) when the frame should initially be displayed. | |
qint64 | endTime () const |
Returns the presentation time (in microseconds) when a frame should stop being displayed. | |
void | setEndTime (qint64 time) |
Sets the presentation time (in microseconds) when a frame should stop being displayed. | |
void | setRotationAngle (RotationAngle) |
Sets the angle the frame should be rotated clockwise before displaying. | |
RotationAngle | rotationAngle () const |
Returns the angle the frame should be rotated clockwise before displaying. | |
void | setMirrored (bool) |
Sets the mirrored flag for the frame. | |
bool | mirrored () const |
Returns whether the frame should be mirrored before displaying. | |
QImage | toImage () const |
Based on the pixel format converts current video frame to image. | |
QString | subtitleText () const |
Returns the subtitle text that should be rendered together with this video frame. | |
void | setSubtitleText (const QString &text) |
Sets the subtitle text that should be rendered together with this video frame to text. | |
void | paint (QPainter *painter, const QRectF &rect, const PaintOptions &options) |
Uses a QPainter, {painter}, to render this QVideoFrame to rect. | |
QVideoFrame (QAbstractVideoBuffer *buffer, const QVideoFrameFormat &format) | |
QAbstractVideoBuffer * | videoBuffer () const |
The QVideoFrame class represents a frame of video data.
\inmodule QtMultimedia
A QVideoFrame encapsulates the pixel data of a video frame, and information about the frame.
Video frames can come from several places - decoded \l {QMediaPlayer}{media}, a \l {QCamera}{camera}, or generated programmatically. The way pixels are described in these frames can vary greatly, and some pixel formats offer greater compression opportunities at the expense of ease of use.
The pixel contents of a video frame can be mapped to memory using the map() function. After a successful call to map(), the video data can be accessed through various functions. Some of the YUV pixel formats provide the data in several planes. The planeCount() method will return the amount of planes that being used.
While mapped, the video data of each plane can accessed using the bits() function, which returns a pointer to a buffer. The size of this buffer is given by the mappedBytes() function, and the size of each line is given by bytesPerLine(). The return value of the handle() function may also be used to access frame data using the internal buffer's native APIs (for example - an OpenGL texture handle).
A video frame can also have timestamp information associated with it. These timestamps can be used to determine when to start and stop displaying the frame.
QVideoFrame objects can consume a significant amount of memory or system resources and should not be held for longer than required by the application.
Definition at line 25 of file qvideoframe.h.
Identifies the type of a video buffers handle.
\value NoHandle The buffer has no handle, its data can only be accessed by mapping the buffer. \value RhiTextureHandle The handle of the buffer is defined by The Qt Rendering Hardware Interface (RHI). RHI is Qt's internal graphics abstraction for 3D APIs, such as OpenGL, Vulkan, Metal, and Direct 3D.
Enumerator | |
---|---|
NoHandle | |
RhiTextureHandle |
Definition at line 29 of file qvideoframe.h.
enum QVideoFrame::MapMode |
Enumerates how a video buffer's data is mapped to system memory.
\value NotMapped The video buffer is not mapped to memory. \value ReadOnly The mapped memory is populated with data from the video buffer when mapped, but the content of the mapped memory may be discarded when unmapped. \value WriteOnly The mapped memory is uninitialized when mapped, but the possibly modified content will be used to populate the video buffer when unmapped. \value ReadWrite The mapped memory is populated with data from the video buffer, and the video buffer is repopulated with the content of the mapped memory when it is unmapped.
Enumerator | |
---|---|
NotMapped | |
ReadOnly | |
WriteOnly | |
ReadWrite |
Definition at line 35 of file qvideoframe.h.
The angle of the clockwise rotation that should be applied to a video frame before displaying.
\value Rotation0 No rotation required, the frame has correct orientation \value Rotation90 The frame should be rotated by 90 degrees \value Rotation180 The frame should be rotated by 180 degrees \value Rotation270 The frame should be rotated by 270 degrees
Enumerator | |
---|---|
Rotation0 | |
Rotation90 | |
Rotation180 | |
Rotation270 |
Definition at line 43 of file qvideoframe.h.
QVideoFrame::QVideoFrame | ( | ) |
Constructs a null video frame.
Definition at line 95 of file qvideoframe.cpp.
QVideoFrame::QVideoFrame | ( | const QVideoFrameFormat & | format | ) |
Constructs a video frame of the given pixel format.
Definition at line 123 of file qvideoframe.cpp.
References QVideoFramePrivate::buffer, QVideoTextureHelper::TextureDescription::bytesForSize(), QVideoTextureHelper::TextureDescription::strideForWidth(), and QVideoTextureHelper::textureDescription().
|
default |
Constructs a shallow copy of other.
Since QVideoFrame is explicitly shared, these two instances will reflect the same frame.
|
default |
Destroys a video frame.
|
defaultnoexcept |
Constructs a QVideoFrame by moving from other.
QVideoFrame::QVideoFrame | ( | QAbstractVideoBuffer * | buffer, |
const QVideoFrameFormat & | format | ||
) |
Constructs a video frame from a buffer with the given pixel format and size in pixels.
Definition at line 105 of file qvideoframe.cpp.
References QVideoFramePrivate::buffer.
uchar * QVideoFrame::bits | ( | int | plane | ) |
Returns a pointer to the start of the frame data buffer for a plane.
This value is only valid while the frame data is \l {map()}{mapped}.
Changes made to data accessed via this pointer (when mapped with write access) are only guaranteed to have been persisted when unmap() is called and when the buffer has been mapped for writing.
Definition at line 520 of file qvideoframe.cpp.
References QAbstractVideoBuffer::MapData::data, QVideoFramePrivate::mapData, and QAbstractVideoBuffer::MapData::nPlanes.
Referenced by convertJPEG(), and QSGVivanteVideoMaterial::vivanteMapping().
const uchar * QVideoFrame::bits | ( | int | plane | ) | const |
Returns a pointer to the start of the frame data buffer for a plane.
This value is only valid while the frame data is \l {map()}{mapped}.
If the buffer was not mapped with read access, the contents of this buffer will initially be uninitialized.
Definition at line 538 of file qvideoframe.cpp.
References QAbstractVideoBuffer::MapData::data, QVideoFramePrivate::mapData, and QAbstractVideoBuffer::MapData::nPlanes.
int QVideoFrame::bytesPerLine | ( | int | plane | ) | const |
Returns the number of bytes in a scan line of a plane.
This value is only valid while the frame data is \l {map()}{mapped}.
Definition at line 501 of file qvideoframe.cpp.
References QAbstractVideoBuffer::MapData::bytesPerLine, QVideoFramePrivate::mapData, and QAbstractVideoBuffer::MapData::nPlanes.
Referenced by QSGVivanteVideoMaterial::vivanteMapping().
qint64 QVideoFrame::endTime | ( | ) | const |
Returns the presentation time (in microseconds) when a frame should stop being displayed.
An invalid time is represented as -1.
Definition at line 605 of file qvideoframe.cpp.
References QVideoFramePrivate::endTime.
QVideoFrame::HandleType QVideoFrame::handleType | ( | ) | const |
Returns the type of a video frame's handle.
The handle type could either be NoHandle, meaning that the frame is memory based, or a RHI texture.
Definition at line 226 of file qvideoframe.cpp.
References QVideoFramePrivate::buffer, QAbstractVideoBuffer::handleType(), and NoHandle.
Referenced by QQuickVideoOutput::updatePaintNode().
int QVideoFrame::height | ( | ) | const |
Returns the height of a video frame.
Definition at line 250 of file qvideoframe.cpp.
References QSize::height(), and size().
Referenced by convertCPU(), map(), and QSGVivanteVideoMaterial::vivanteMapping().
bool QVideoFrame::isMapped | ( | ) | const |
Identifies if a video frame's contents are currently mapped to system memory.
This is a convenience function which checks that the \l {QVideoFrame::MapMode}{MapMode} of the frame is not equal to QVideoFrame::NotMapped.
Returns true if the contents of the video frame are mapped to system memory, and false otherwise.
Definition at line 267 of file qvideoframe.cpp.
References QVideoFramePrivate::buffer, QAbstractVideoBuffer::mapMode(), and NotMapped.
bool QVideoFrame::isReadable | ( | ) | const |
Identifies if the mapped contents of a video frame were read from the frame when it was mapped.
This is a convenience function which checks if the \l {QVideoFrame::MapMode}{MapMode} contains the QVideoFrame::WriteOnly flag.
Returns true if the contents of the mapped memory were read from the video frame, and false otherwise.
Definition at line 302 of file qvideoframe.cpp.
References QVideoFramePrivate::buffer, QAbstractVideoBuffer::mapMode(), and ReadOnly.
bool QVideoFrame::isValid | ( | ) | const |
Identifies whether a video frame is valid.
An invalid frame has no video buffer associated with it.
Returns true if the frame is valid, and false if it is not.
Definition at line 199 of file qvideoframe.cpp.
References QVideoFramePrivate::buffer, QVideoFramePrivate::format, QVideoFrameFormat::Format_Invalid, and QVideoFrameFormat::pixelFormat().
Referenced by QSGVivanteVideoMaterial::bind(), paint(), AVFCameraRenderer::syncHandleViewfinderFrame(), toImage(), QQuickVideoOutput::updatePaintNode(), and QVideoWindowPrivate::updateTextures().
bool QVideoFrame::isWritable | ( | ) | const |
Identifies if the mapped contents of a video frame will be persisted when the frame is unmapped.
This is a convenience function which checks if the \l {QVideoFrame::MapMode}{MapMode} contains the QVideoFrame::WriteOnly flag.
Returns true if the video frame will be updated when unmapped, and false otherwise.
Definition at line 286 of file qvideoframe.cpp.
References QVideoFramePrivate::buffer, QAbstractVideoBuffer::mapMode(), and WriteOnly.
bool QVideoFrame::map | ( | QVideoFrame::MapMode | mode | ) |
Maps the contents of a video frame to system (CPU addressable) memory.
In some cases the video frame data might be stored in video memory or otherwise inaccessible memory, so it is necessary to map a frame before accessing the pixel data. This may involve copying the contents around, so avoid mapping and unmapping unless required.
The map mode indicates whether the contents of the mapped memory should be read from and/or written to the frame. If the map mode includes the QVideoFrame::ReadOnly
flag the mapped memory will be populated with the content of the video frame when initially mapped. If the map mode includes the QVideoFrame::WriteOnly
flag the content of the possibly modified mapped memory will be written back to the frame when unmapped.
While mapped the contents of a video frame can be accessed directly through the pointer returned by the bits() function.
When access to the data is no longer needed, be sure to call the unmap() function to release the mapped memory and possibly update the video frame contents.
If the video frame has been mapped in read only mode, it is permissible to map it multiple times in read only mode (and unmap it a corresponding number of times). In all other cases it is necessary to unmap the frame first before mapping a second time.
Returns true if the frame was mapped to memory in the given mode and false otherwise.
Definition at line 347 of file qvideoframe.cpp.
References QVideoFramePrivate::buffer, QAbstractVideoBuffer::MapData::bytesPerLine, QAbstractVideoBuffer::MapData::data, QVideoFramePrivate::format, QVideoFrameFormat::Format_ABGR8888, QVideoFrameFormat::Format_ARGB8888, QVideoFrameFormat::Format_ARGB8888_Premultiplied, QVideoFrameFormat::Format_AYUV, QVideoFrameFormat::Format_AYUV_Premultiplied, QVideoFrameFormat::Format_BGRA8888, QVideoFrameFormat::Format_BGRA8888_Premultiplied, QVideoFrameFormat::Format_BGRX8888, QVideoFrameFormat::Format_IMC1, QVideoFrameFormat::Format_IMC2, QVideoFrameFormat::Format_IMC3, QVideoFrameFormat::Format_IMC4, QVideoFrameFormat::Format_Invalid, QVideoFrameFormat::Format_Jpeg, QVideoFrameFormat::Format_NV12, QVideoFrameFormat::Format_NV21, QVideoFrameFormat::Format_P010, QVideoFrameFormat::Format_P016, QVideoFrameFormat::Format_RGBA8888, QVideoFrameFormat::Format_RGBX8888, QVideoFrameFormat::Format_SamplerExternalOES, QVideoFrameFormat::Format_SamplerRect, QVideoFrameFormat::Format_UYVY, QVideoFrameFormat::Format_XBGR8888, QVideoFrameFormat::Format_XRGB8888, QVideoFrameFormat::Format_Y16, QVideoFrameFormat::Format_Y8, QVideoFrameFormat::Format_YUV420P, QVideoFrameFormat::Format_YUV420P10, QVideoFrameFormat::Format_YUV422P, QVideoFrameFormat::Format_YUYV, QVideoFrameFormat::Format_YV12, height(), lock, QAbstractVideoBuffer::map(), QVideoFramePrivate::mapData, QAbstractVideoBuffer::mapMode(), QVideoFramePrivate::mapMutex, QVideoFramePrivate::mappedCount, NotMapped, QAbstractVideoBuffer::MapData::nPlanes, QVideoFrameFormat::pixelFormat(), Q_ASSERT, ReadOnly, and QAbstractVideoBuffer::MapData::size.
Referenced by convertCPU(), convertJPEG(), and QSGVivanteVideoMaterial::vivanteMapping().
QVideoFrame::MapMode QVideoFrame::mapMode | ( | ) | const |
Returns the mode a video frame was mapped to system memory in.
Definition at line 312 of file qvideoframe.cpp.
References QVideoFramePrivate::buffer, QAbstractVideoBuffer::mapMode(), and NotMapped.
int QVideoFrame::mappedBytes | ( | int | plane | ) | const |
Returns the number of bytes occupied by plane plane of the mapped frame data.
This value is only valid while the frame data is \l {map()}{mapped}.
Definition at line 552 of file qvideoframe.cpp.
References QVideoFramePrivate::mapData, QAbstractVideoBuffer::MapData::nPlanes, and QAbstractVideoBuffer::MapData::size.
Referenced by convertJPEG().
bool QVideoFrame::mirrored | ( | ) | const |
Returns whether the frame should be mirrored before displaying.
Definition at line 666 of file qvideoframe.cpp.
References QVideoFramePrivate::mirrored.
Referenced by QVideoWindowPrivate::render(), setMirrored(), QSGVideoNode::setTexturedRectGeometry(), and toImage().
bool QVideoFrame::operator!= | ( | const QVideoFrame & | other | ) | const |
true
if this QVideoFrame and other do not reflect the same frame. Definition at line 182 of file qvideoframe.cpp.
References other().
|
default |
Moves other into this QVideoFrame.
Assigns the contents of other to this video frame.
Since QVideoFrame is explicitly shared, these two instances will reflect the same frame.
bool QVideoFrame::operator== | ( | const QVideoFrame & | other | ) | const |
true
if this QVideoFrame and other reflect the same frame. Definition at line 173 of file qvideoframe.cpp.
References other().
void QVideoFrame::paint | ( | QPainter * | painter, |
const QRectF & | rect, | ||
const PaintOptions & | options | ||
) |
Uses a QPainter, {painter}, to render this QVideoFrame to rect.
The PaintOptions options can be used to specify a background color and how rect should be filled with the video.
Definition at line 713 of file qvideoframe.cpp.
References QVideoFrame::PaintOptions::aspectRatioMode, QVideoFrame::PaintOptions::backgroundColor, Qt::black, QRectF::bottom(), QRectF::center(), QVideoFrame::PaintOptions::DontDrawSubtitles, QPainter::drawImage(), QPainter::fillRect(), QRectF::height(), QString::isEmpty(), isValid(), Qt::KeepAspectRatio, layout, QRectF::left(), QChar::LineSeparator, map, QRectF::moveCenter(), painter, QVideoFrame::PaintOptions::paintFlags, ReadOnly, rect, QString::replace(), QRectF::right(), rotationAngle(), QPainter::setTransform(), size(), QRectF::size(), QVideoFramePrivate::subtitleText, text, this, toImage(), QRectF::top(), QRectF::topLeft(), QSizeF::toSize(), QPainter::transform(), QTransform::translate(), Qt::transparent, QSizeF::transpose(), unmap(), QLayout::update(), QPointF::x(), and QPointF::y().
Referenced by QVideoWindowPrivate::render().
QVideoFrameFormat::PixelFormat QVideoFrame::pixelFormat | ( | ) | const |
Returns the pixel format of this video frame.
Definition at line 207 of file qvideoframe.cpp.
References QVideoFramePrivate::format, QVideoFrameFormat::Format_Invalid, and QVideoFrameFormat::pixelFormat().
Referenced by convertCPU(), QQuickVideoOutput::updatePaintNode(), and QSGVivanteVideoMaterial::vivanteMapping().
int QVideoFrame::planeCount | ( | ) | const |
Returns the number of planes in the video frame.
Definition at line 566 of file qvideoframe.cpp.
References QVideoFramePrivate::format, and QVideoFrameFormat::planeCount().
Referenced by QSGVivanteVideoMaterial::vivanteMapping().
QVideoFrame::RotationAngle QVideoFrame::rotationAngle | ( | ) | const |
Returns the angle the frame should be rotated clockwise before displaying.
Definition at line 649 of file qvideoframe.cpp.
References Rotation0, and QVideoFramePrivate::rotationAngle.
Referenced by paint(), QVideoWindowPrivate::render(), QSGVideoNode::setTexturedRectGeometry(), and toImage().
Sets the presentation time (in microseconds) when a frame should stop being displayed.
An invalid time is represented as -1.
Definition at line 618 of file qvideoframe.cpp.
References QVideoFramePrivate::endTime, and time.
Referenced by QAndroidCamera::frameAvailable(), and QFFmpeg::VideoRenderer::renderInternal().
void QVideoFrame::setMirrored | ( | bool | mirrored | ) |
Sets the mirrored flag for the frame.
Definition at line 657 of file qvideoframe.cpp.
References QVideoFramePrivate::mirrored, and mirrored().
Referenced by QAndroidCamera::frameAvailable().
void QVideoFrame::setRotationAngle | ( | QVideoFrame::RotationAngle | angle | ) |
Sets the angle the frame should be rotated clockwise before displaying.
Definition at line 640 of file qvideoframe.cpp.
References QVideoFramePrivate::rotationAngle.
Referenced by QAndroidCamera::frameAvailable().
Sets the presentation time (in microseconds) when the frame should initially be displayed.
An invalid time is represented as -1.
Definition at line 592 of file qvideoframe.cpp.
References QVideoFramePrivate::startTime, and time.
Referenced by QAndroidCamera::frameAvailable(), and QFFmpeg::VideoRenderer::renderInternal().
Sets the subtitle text that should be rendered together with this video frame to text.
Definition at line 698 of file qvideoframe.cpp.
References QVideoFramePrivate::subtitleText, and text.
Referenced by QPlatformVideoSink::setVideoFrame().
QSize QVideoFrame::size | ( | ) | const |
Returns the dimensions of a video frame.
Definition at line 234 of file qvideoframe.cpp.
References QVideoFramePrivate::format, and QVideoFrameFormat::frameSize().
Referenced by height(), paint(), QVideoWindowPrivate::render(), and width().
qint64 QVideoFrame::startTime | ( | ) | const |
Returns the presentation time (in microseconds) when the frame should be displayed.
An invalid time is represented as -1.
Definition at line 579 of file qvideoframe.cpp.
References QVideoFramePrivate::startTime.
QString QVideoFrame::subtitleText | ( | ) | const |
Returns the subtitle text that should be rendered together with this video frame.
Definition at line 690 of file qvideoframe.cpp.
References QVideoFramePrivate::subtitleText.
Referenced by QVideoWindowPrivate::updateSubtitle().
QVideoFrameFormat QVideoFrame::surfaceFormat | ( | ) | const |
Returns the surface format of this video frame.
Definition at line 215 of file qvideoframe.cpp.
References QVideoFramePrivate::format.
Referenced by QVideoWindowPrivate::render(), toImage(), and QVideoWindowPrivate::updateTextures().
|
inlinenoexcept |
Swaps the current video frame with other.
Definition at line 58 of file qvideoframe.h.
QImage QVideoFrame::toImage | ( | ) | const |
Based on the pixel format converts current video frame to image.
Definition at line 675 of file qvideoframe.cpp.
References QVideoFramePrivate::image, QImage::isNull(), isValid(), mirrored(), qImageFromVideoFrame(), rotationAngle(), surfaceFormat(), and QVideoFrameFormat::TopToBottom.
Referenced by paint().
void QVideoFrame::unmap | ( | ) |
Releases the memory mapped by the map() function.
If the \l {QVideoFrame::MapMode}{MapMode} included the QVideoFrame::WriteOnly flag this will persist the current content of the mapped memory to the video frame.
unmap() should not be called if map() function failed.
Definition at line 472 of file qvideoframe.cpp.
References QVideoFramePrivate::buffer, lock, QVideoFramePrivate::mapData, QVideoFramePrivate::mapMutex, QVideoFramePrivate::mappedCount, qWarning, and QAbstractVideoBuffer::unmap().
Referenced by convertCPU(), convertJPEG(), and paint().
QAbstractVideoBuffer * QVideoFrame::videoBuffer | ( | ) | const |
Definition at line 114 of file qvideoframe.cpp.
References QVideoFramePrivate::buffer.
int QVideoFrame::width | ( | ) | const |
Returns the width of a video frame.
Definition at line 242 of file qvideoframe.cpp.
References size(), and QSize::width().
Referenced by convertCPU(), and QSGVivanteVideoMaterial::vivanteMapping().