![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QVideoFrame class represents a frame of video data. More...
#include <qvideoframe.h>
Classes | |
| struct | PaintOptions |
Public Types | |
| enum | MapMode { NotMapped = 0x00 , ReadOnly = 0x01 , WriteOnly = 0x02 , ReadWrite = ReadOnly | WriteOnly } |
| Enumerates how a video buffer's data is mapped to system memory. More... | |
Public Member Functions | |
| QVideoFrame () | |
| Constructs a null video frame. | |
| QVideoFrame (const QVideoFrameFormat &formatformat) | |
| Constructs a video frame of the given pixel format. | |
| QVideoFrame (const QImage &imageimage) | |
| Constructs a QVideoFrame from a QImage. | |
| QVideoFrame (std::unique_ptr< QAbstractVideoBuffer > videoBuffer) | |
| Constructs a QVideoFrame from a \l QAbstractVideoBuffer. | |
| 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. | |
| 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 modemode) |
| 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 | setRotation (QtVideo::Rotation angleangle) |
| Sets the angle the frame should be rotated clockwise before displaying. | |
| QtVideo::Rotation | rotation () const |
| Returns the angle the frame should be rotated clockwise before displaying. | |
| void | setMirrored (bool) |
| Sets whether the frame should be mirrored around its vertical axis before displaying. | |
| bool | mirrored () const |
| Returns whether the frame should be mirrored around its vertical axis before displaying. | |
| void | setStreamFrameRate (qreal raterate) |
| Sets the frame rate of a video stream in frames per second. | |
| qreal | streamFrameRate () const |
| Returns the frame rate of a video stream in frames per second. | |
| QImage | toImage () const |
| Converts current video frame to image. | |
| QVideoFrame | copyToCpuMemory () const |
| Returns a deep copy of this video frame, with its pixel data held in CPU memory. | |
| 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. | |
Friends | |
| class | QVideoFramePrivate |
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.
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.
Definition at line 26 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 40 of file qvideoframe.h.
| QVideoFrame::QVideoFrame | ( | ) |
Constructs a null video frame.
Definition at line 99 of file qvideoframe.cpp.
| QVideoFrame::QVideoFrame | ( | const QVideoFrameFormat & | format | ) |
Constructs a video frame of the given pixel format.
Definition at line 130 of file qvideoframe.cpp.
|
explicit |
Constructs a QVideoFrame from a QImage.
If the QImage::Format matches one of the formats in QVideoFrameFormat::PixelFormat, the QVideoFrame will hold an instance of the image and use that format without any pixel format conversion. In this case, pixel data will be copied only if you call \l{QVideoFrame::map} with WriteOnly flag while keeping the original image.
Otherwise, if the QImage::Format matches none of video formats, the image is first converted to a supported (A)RGB format using QImage::convertedTo() with the Qt::AutoColor flag. This may incur a performance penalty.
If QImage::isNull() evaluates to true for the input QImage, the QVideoFrame will be invalid and QVideoFrameFormat::isValid() will return false.
Definition at line 169 of file qvideoframe.cpp.
|
explicit |
Constructs a QVideoFrame from a \l QAbstractVideoBuffer.
The specified videoBuffer refers to an instance a reimplemented \l QAbstractVideoBuffer. The instance is expected to contain a preallocated custom video buffer and must implement \l QAbstractVideoBuffer::format, \l QAbstractVideoBuffer::map, and \l QAbstractVideoBuffer::unmap for GPU content.
If videoBuffer is null or gets an invalid \l QVideoFrameFormat, the constructors creates an invalid video frame.
The created frame will hold ownership of the specified video buffer for its lifetime. Considering that QVideoFrame is implemented via a shared private object, the specified video buffer will be destroyed upon destruction of the last copy of the created video frame.
Note, if a video frame has been passed to \l QMediaRecorder or a rendering pipeline, the lifetime of the frame is undefined, and the media recorder can destroy it in a different thread.
QVideoFrame will contain own instance of QVideoFrameFormat. Upon invoking \l setStreamFrameRate, \l setMirrored, or \l setRotation, the inner format can be modified, and \l surfaceFormat will return a detached instance.
Definition at line 220 of file qvideoframe.cpp.
|
default |
Constructs a shallow copy of other.
The two instances refer to the same frame, see \l {QVideoFrame#Explicit Sharing}{explicit sharing}.
|
default |
Destroys a video frame.
|
defaultnoexcept |
Constructs a QVideoFrame by moving from other.
| 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 659 of file qvideoframe.cpp.
| 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 677 of file qvideoframe.cpp.
| 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 640 of file qvideoframe.cpp.
| QVideoFrame QVideoFrame::copyToCpuMemory | ( | ) | const |
Returns a deep copy of this video frame, with its pixel data held in CPU memory.
Unlike the copy constructor, the returned frame is not shared with this frame, see \l {QVideoFrame#Explicit Sharing}{explicit sharing}.
The copy has the same size, pixel format, timing, subtitle text and rotation/mirroring as this frame. Mapping the copy with \l map() does not involve the hardware that produced this frame.
Copying a frame that is backed by hardware memory reads the frame back to CPU memory, which can be expensive.
Definition at line 915 of file qvideoframe.cpp.
| 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 744 of file qvideoframe.cpp.
| int QVideoFrame::height | ( | ) | const |
Returns the height of a video frame.
Definition at line 356 of file qvideoframe.cpp.
| 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 373 of file qvideoframe.cpp.
| 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 408 of file qvideoframe.cpp.
| 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 299 of file qvideoframe.cpp.
| 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 392 of file qvideoframe.cpp.
| 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. A mapping should only be held for a short time and be released as early as possible.
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 475 of file qvideoframe.cpp.
| QVideoFrame::MapMode QVideoFrame::mapMode | ( | ) | const |
Returns the mode a video frame was mapped to system memory in.
Definition at line 439 of file qvideoframe.cpp.
| 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 691 of file qvideoframe.cpp.
| bool QVideoFrame::mirrored | ( | ) | const |
Returns whether the frame should be mirrored around its vertical axis before displaying.
Transformations of QVideoFrame, specifically rotation and mirroring, are used only for displaying the video frame and are applied on top of the surface transformation, which is determined by \l QVideoFrameFormat. Mirroring is applied after rotation.
Mirroring is typically needed for video frames coming from a front camera of a mobile device.
Definition at line 852 of file qvideoframe.cpp.
| bool QVideoFrame::operator!= | ( | const QVideoFrame & | other | ) | const |
true if this QVideoFrame and other do not reflect the same frame. Definition at line 282 of file qvideoframe.cpp.
|
default |
Moves other into this QVideoFrame.
Assigns a shallow copy of other to this video frame.
Both instances refer to the same frame, see \l {QVideoFrame#Explicit Sharing}{explicit sharing}.
| bool QVideoFrame::operator== | ( | const QVideoFrame & | other | ) | const |
true if this QVideoFrame and other reflect the same frame. Definition at line 273 of file qvideoframe.cpp.
| 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 946 of file qvideoframe.cpp.
| QVideoFrameFormat::PixelFormat QVideoFrame::pixelFormat | ( | ) | const |
Returns the pixel format of this video frame.
Definition at line 307 of file qvideoframe.cpp.
| int QVideoFrame::planeCount | ( | ) | const |
Returns the number of planes in the video frame.
Definition at line 705 of file qvideoframe.cpp.
| QtVideo::Rotation QVideoFrame::rotation | ( | ) | const |
Returns the angle the frame should be rotated clockwise before displaying.
Transformations of QVideoFrame, specifically rotation and mirroring, are used only for displaying the video frame and are applied on top of the surface transformation, which is determined by \l QVideoFrameFormat. Rotation is applied before mirroring.
Definition at line 819 of file qvideoframe.cpp.
Sets the presentation time (in microseconds) when a frame should stop being displayed.
An invalid time is represented as -1.
Definition at line 757 of file qvideoframe.cpp.
| void QVideoFrame::setMirrored | ( | bool | mirrored | ) |
Sets whether the frame should be mirrored around its vertical axis before displaying.
Transformations of QVideoFrame, specifically rotation and mirroring, are used only for displaying the video frame and are applied on top of the surface transformation, which is determined by \l QVideoFrameFormat. Mirroring is applied after rotation.
Mirroring is typically needed for video frames coming from a front camera of a mobile device.
Default value is false.
Definition at line 836 of file qvideoframe.cpp.
| void QVideoFrame::setRotation | ( | QtVideo::Rotation | angle | ) |
Sets the angle the frame should be rotated clockwise before displaying.
Transformations of QVideoFrame, specifically rotation and mirroring, are used only for displaying the video frame and are applied on top of the surface transformation, which is determined by \l QVideoFrameFormat. Rotation is applied before mirroring.
Default value is QtVideo::Rotation::None.
Definition at line 805 of file qvideoframe.cpp.
Sets the presentation time (in microseconds) when the frame should initially be displayed.
An invalid time is represented as -1.
Definition at line 731 of file qvideoframe.cpp.
Sets the frame rate of a video stream in frames per second.
Definition at line 860 of file qvideoframe.cpp.
Sets the subtitle text that should be rendered together with this video frame to text.
Definition at line 931 of file qvideoframe.cpp.
| QSize QVideoFrame::size | ( | ) | const |
Returns the dimensions of a video frame.
Definition at line 340 of file qvideoframe.cpp.
| 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 718 of file qvideoframe.cpp.
| qreal QVideoFrame::streamFrameRate | ( | ) | const |
Returns the frame rate of a video stream in frames per second.
Definition at line 869 of file qvideoframe.cpp.
| QString QVideoFrame::subtitleText | ( | ) | const |
Returns the subtitle text that should be rendered together with this video frame.
Definition at line 923 of file qvideoframe.cpp.
| QVideoFrameFormat QVideoFrame::surfaceFormat | ( | ) | const |
Returns the surface format of this video frame.
Definition at line 315 of file qvideoframe.cpp.
|
inlinenoexcept |
Swaps the current video frame with other.
Definition at line 68 of file qvideoframe.h.
| QImage QVideoFrame::toImage | ( | ) | const |
Converts current video frame to image.
The conversion is based on the current pixel data and the \l {QVideoFrame::surfaceFormat}{surface format}. Transformations of the frame don't impact the result since they are applied for presentation only.
Definition at line 884 of file qvideoframe.cpp.
| 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 610 of file qvideoframe.cpp.
| int QVideoFrame::width | ( | ) | const |
Returns the width of a video frame.
Definition at line 348 of file qvideoframe.cpp.
|
friend |
Definition at line 159 of file qvideoframe.h.