QVideoFrame 類錶示視頻數據幀。 更多...
| 頭: |
#include <QVideoFrame>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
|
| qmake: |
QT += multimedia
|
| enum | HandleType { NoHandle, RhiTextureHandle } |
| enum | MapMode { NotMapped, ReadOnly, WriteOnly, ReadWrite } |
| QVideoFrame () | |
(從 6.8 起)
|
QVideoFrame (const QImage & image ) |
| QVideoFrame (const QVideoFrameFormat & format ) | |
(從 6.8 起)
|
QVideoFrame (std::unique_ptr<QAbstractVideoBuffer> videoBuffer ) |
| QVideoFrame (const QVideoFrame & other ) | |
| QVideoFrame (QVideoFrame && other ) | |
| ~QVideoFrame () | |
| uchar * | bits (int plane ) |
| const uchar * | bits (int plane ) const |
| int | bytesPerLine (int plane ) const |
| qint64 | endTime () const |
| QVideoFrame::HandleType | handleType () const |
| int | height () const |
| bool | isMapped () const |
| bool | isReadable () const |
| bool | isValid () const |
| bool | isWritable () const |
| bool | map (QVideoFrame::MapMode mode ) |
| QVideoFrame::MapMode | mapMode () const |
| int | mappedBytes (int plane ) const |
| bool | mirrored () const |
| void | paint (QPainter * painter , const QRectF & rect , const QVideoFrame::PaintOptions & options ) |
| QVideoFrameFormat::PixelFormat | pixelFormat () const |
| int | planeCount () const |
| QtVideo::Rotation | rotation () const |
| void | setEndTime (qint64 time ) |
| void | setMirrored (bool mirrored ) |
| void | setRotation (QtVideo::Rotation angle ) |
| void | setStartTime (qint64 time ) |
| void | setStreamFrameRate (qreal rate ) |
| void | setSubtitleText (const QString & text ) |
| QSize | size () const |
| qint64 | startTime () const |
| qreal | streamFrameRate () const |
| QString | subtitleText () const |
| QVideoFrameFormat | surfaceFormat () const |
| void | swap (QVideoFrame & other ) |
| QImage | toImage () const |
| void | unmap () |
| int | width () const |
| bool | operator!= (const QVideoFrame & other ) const |
| QVideoFrame & | operator= (QVideoFrame && other ) |
| QVideoFrame & | operator= (const QVideoFrame & other ) |
| bool | operator== (const QVideoFrame & other ) const |
QVideoFrame 封裝視頻幀的像素數據,及幀的有關信息。
視頻幀可以來自幾個地方 - 解碼的 media , camera ,或以編程方式生成。在這些幀中描述像素的方式可能有很大不同,且一些像素格式以易用性為代價提供更大壓縮機會。
視頻幀的像素內容映射到內存可以使用 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 () 函數,和每行大小的給定是通過 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.
注意: 由於 QVideoFrame 是明確共享的,要拷貝的視頻幀可能很昂貴,所以對視頻幀所做的任何改變也將應用於任何副本。
另請參閱 QAbstractVideoBuffer , QVideoFrameFormat ,和 QVideoFrame::MapMode .
標識視頻緩衝句柄的類型。
| 常量 | 值 | 描述 |
|---|---|---|
QVideoFrame::NoHandle
|
0
|
緩衝沒有句柄,隻能通過映射緩衝訪問其數據。 |
QVideoFrame::RhiTextureHandle
|
1
|
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. |
另請參閱 handleType ().
枚舉如何把視頻緩衝數據映射到係統內存。
| 常量 | 值 | 描述 |
|---|---|---|
QVideoFrame::NotMapped
|
0x00
|
不把視頻緩衝映射到內存。 |
QVideoFrame::ReadOnly
|
0x01
|
采用來自視頻緩衝的數據填充映射內存當映射時,但可能丟棄所映射內存的內容當取消映射時。 |
QVideoFrame::WriteOnly
|
0x02
|
映射內存未初始化當映射時,但可能修改的內容將用於填充視頻緩衝當取消映射時。 |
QVideoFrame::ReadWrite
|
ReadOnly | WriteOnly
|
采用來自視頻緩衝的數據填充映射內存,並采用映射內存的內容重新填充視頻緩衝當取消映射時。 |
構造 null 視頻幀。
[explicit, since 6.8]
QVideoFrame::
QVideoFrame
(const
QImage
&
image
)
Constructs a QVideoFrame from a QImage .
若
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
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 () 采用 Qt::AutoColor flag. This may incur a performance penalty.
若 QImage::isNull () evaluates to true for the input QImage , the QVideoFrame will be invalid and QVideoFrameFormat::isValid () 將返迴 false。
該函數在 Qt 6.8 引入。
另請參閱 QVideoFrameFormat::pixelFormatFromImageFormat (), QImage::convertedTo (),和 QImage::isNull ().
構造視頻幀采用給定像素 format .
[explicit, since 6.8]
QVideoFrame::
QVideoFrame
(
std::unique_ptr
<
QAbstractVideoBuffer
>
videoBuffer
)
Constructs a QVideoFrame from a QAbstractVideoBuffer .
指定 videoBuffer refers to an instance a reimplemented QAbstractVideoBuffer . The instance is expected to contain a preallocated custom video buffer and must implement QAbstractVideoBuffer::format , QAbstractVideoBuffer::map ,和 QAbstractVideoBuffer::unmap for GPU content.
若 videoBuffer is null or gets an invalid 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 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 setStreamFrameRate , setMirrored ,或 setRotation , the inner format can be modified, and surfaceFormat will return a detached instance.
該函數在 Qt 6.8 引入。
另請參閱 QAbstractVideoBuffer and QVideoFrameFormat .
構造淺拷貝為 other 。由於 QVideoFrame 是明確共享的,所以這 2 實例將反射相同幀。
[noexcept]
QVideoFrame::
QVideoFrame
(
QVideoFrame
&&
other
)
Constructs a QVideoFrame by moving from other .
[noexcept]
QVideoFrame::
~QVideoFrame
()
銷毀視頻幀。
返迴指針指嚮幀數據緩衝的開始為 plane .
此值纔有效當幀數據為 mapped .
憑藉此指針訪問數據做齣的改變 (當采用寫入訪問映射時) 隻保證有持久化當 unmap () 被調用和當緩衝已被映射以供寫入。
另請參閱 map (), mappedBytes (), bytesPerLine (),和 planeCount ().
返迴指針指嚮幀數據緩衝的開始為 plane .
此值纔有效當幀數據為 mapped .
若緩衝未采用讀取訪問被映射,此緩衝的內容將被初始為未被初始化。
另請參閱 map (), mappedBytes (), bytesPerLine (),和 planeCount ().
Returns the number of bytes in a scan line of a plane .
此值纔有效當幀數據為 mapped .
另請參閱 bits (), map (), mappedBytes (),和 planeCount ().
返迴要顯示的呈現時間 (以微秒為單位),當幀應停止時。
無效時間錶示為 -1。
另請參閱 setEndTime ().
返迴視頻幀的句柄類型。
The handle type could either be NoHandle , meaning that the frame is memory based, or a RHI texture.
返迴視頻幀的高度。
標識目前是否把視頻幀內容,映射到係統內存。
This is a convenience function which checks that the 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.
另請參閱 mapMode () 和 QVideoFrame::MapMode .
標識視頻幀映射內容,是否是從幀讀取當映射時。
這是方便校驗函數若 MapMode 包含 QVideoFrame::WriteOnly 標誌。
返迴 true 若從視頻幀讀取映射內存內容,和 false 否則。
另請參閱 mapMode () 和 QVideoFrame::MapMode .
標識視頻幀是否有效。
無效幀沒有關聯它的視頻緩衝。
返迴 true 若幀有效,和 false 若幀無效。
標識視頻幀的映射內容是否會持久化,當取消幀映射時。
這是方便校驗函數若 MapMode 包含 QVideoFrame::WriteOnly 標誌。
返迴 true 若將更新視頻幀當取消映射時,否則返迴 false。
注意: 更改以隻讀方式映射幀數據的結果未定義。從屬緩衝實現,改變可能持久化,或更糟更改共享緩衝。
另請參閱 mapMode () 和 QVideoFrame::MapMode .
把視頻幀的內容映射到係統 (CPU 可尋址) 內存。
在某些情況下,視頻幀數據可能存儲在視頻內存 (或其它不可訪問內存) 中,因此有必要映射幀在訪問像素數據前。這可能涉及圍繞內容的拷貝,所以,應避免映射和取消映射 (除非要求)。
映射
mode
指示映射內存內容是否應讀取自和/或寫入幀。若映射模式包括
QVideoFrame::ReadOnly
標誌將采用視頻幀內容填充映射內存當初始映射時。若映射模式包括
QVideoFrame::WriteOnly
標誌可能將修改映射內存內容寫迴到幀當取消映射時。
當映射時,可以直接訪問視頻幀內容透過指針返迴通過 bits () 函數。
當訪問數據不再需要時,確保調用 unmap () 函數以釋放映射內存且可能更新視頻幀內容。
若已以隻讀方式映射視頻幀,則以隻讀方式多次映射 (且取消映射它相應次數) 是準許的。在所有其它情況下,有必要先取消幀映射,在第 2 次映射前。
注意: 由於隻讀寫入映射內存未定義,且可能導緻共享數據改變 (或崩潰)。
返迴 true 若映射幀到內存按給定 mode 和 false 否則。
另請參閱 unmap (), mapMode (),和 bits ().
返迴將視頻幀映射到係統內存中的模式。
另請參閱 map () 和 QVideoFrame::MapMode .
Returns the number of bytes occupied by plane plane of the mapped frame data.
此值纔有效當幀數據為 mapped .
另請參閱 map ().
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
QVideoFrameFormat
. Mirroring is applied after rotation.
Mirroring is typically needed for video frames coming from a front camera of a mobile device.
另請參閱 setMirrored ().
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.
注意: that rendering will usually happen without hardware acceleration when using this method.
Returns the pixel format of this video frame.
返迴視頻幀中的平麵數。
另請參閱 map ().
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
QVideoFrameFormat
. Rotation is applied before mirroring.
另請參閱 setRotation ().
設置呈現 time (以微秒為單位) 當幀應停止顯示時。
無效時間錶示為 -1。
另請參閱 endTime ().
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
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
.
另請參閱 mirrored ().
設置 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
QVideoFrameFormat
. Rotation is applied before mirroring.
Default value is
QtVideo::Rotation::None
.
另請參閱 rotation ().
設置呈現 time (以微秒為單位) 當幀應該被初始顯示時。
無效時間錶示為 -1。
另請參閱 startTime ().
Sets the frame rate of a video stream in frames per second.
另請參閱 streamFrameRate ().
Sets the subtitle text that should be rendered together with this video frame to text .
另請參閱 subtitleText ().
返迴視頻幀尺度。
返迴呈現時間 (以微秒為單位) 當幀應該被顯示時。
無效時間錶示為 -1。
另請參閱 setStartTime ().
Returns the frame rate of a video stream in frames per second.
另請參閱 setStreamFrameRate ().
Returns the subtitle text that should be rendered together with this video frame.
另請參閱 setSubtitleText ().
Returns the surface format of this video frame.
[noexcept]
void
QVideoFrame::
swap
(
QVideoFrame
&
other
)
Swaps the current video frame with other .
Converts current video frame to image.
The conversion is based on the current pixel data and the surface format . Transformations of the frame don't impact the result since they are applied for presentation only.
釋放內存映射通過 map () 函數。
若 MapMode 包括 QVideoFrame::WriteOnly 標誌,則這會把映射內存當前內容堅持到視頻幀。
unmap() 不應被調用,若 map () 函數失敗。
另請參閱 map ().
返迴視頻幀的寬度。
返迴
true
若此
QVideoFrame
and
other
不反射相同幀。
[noexcept]
QVideoFrame
&QVideoFrame::
operator=
(
QVideoFrame
&&
other
)
移動 other 到此 QVideoFrame .
賦值內容對於 other 到此視頻幀。由於 QVideoFrame 是明確共享的,這 2 實例將反射相同幀。
返迴
true
若此
QVideoFrame
and
other
反射相同幀。