QVideoFrame 類

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 }
enum RotationAngle { Rotation0, Rotation90, Rotation180, Rotation270 }

公共函數

QVideoFrame ()
QVideoFrame (const QVideoFrameFormat & format )
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
QVideoFrame::RotationAngle rotationAngle () const
void setEndTime (qint64 time )
void setMirrored (bool mirrored )
void setRotationAngle (QVideoFrame::RotationAngle angle )
void setStartTime (qint64 time )
void setSubtitleText (const QString & text )
QSize size () const
qint64 startTime () 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 是明確共享的,要拷貝的視頻幀可能很昂貴,所以對視頻幀所做的任何改變也將應用於任何副本。

成員類型文檔編製

enum QVideoFrame:: HandleType

標識視頻緩衝句柄的類型。

常量 描述
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 ().

enum QVideoFrame:: MapMode

枚舉如何把視頻緩衝數據映射到係統內存。

常量 描述
QVideoFrame::NotMapped 0x00 不把視頻緩衝映射到內存。
QVideoFrame::ReadOnly 0x01 采用來自視頻緩衝的數據填充映射內存當映射時,但可能丟棄所映射內存的內容當取消映射時。
QVideoFrame::WriteOnly 0x02 映射內存未初始化當映射時,但可能修改的內容將用於填充視頻緩衝當取消映射時。
QVideoFrame::ReadWrite ReadOnly | WriteOnly 采用來自視頻緩衝的數據填充映射內存,並采用映射內存的內容重新填充視頻緩衝當取消映射時。

另請參閱 mapMode () 和 map ().

enum QVideoFrame:: RotationAngle

The angle of the clockwise rotation that should be applied to a video frame before displaying.

常量 描述
QVideoFrame::Rotation0 0 No rotation required, the frame has correct orientation
QVideoFrame::Rotation90 90 The frame should be rotated by 90 degrees
QVideoFrame::Rotation180 180 The frame should be rotated by 180 degrees
QVideoFrame::Rotation270 270 The frame should be rotated by 270 degrees

成員函數文檔編製

QVideoFrame:: QVideoFrame ()

構造 null 視頻幀。

QVideoFrame:: QVideoFrame (const QVideoFrameFormat & format )

構造視頻幀采用給定像素 format .

QVideoFrame:: QVideoFrame (const QVideoFrame & other )

構造淺拷貝為 other 。由於 QVideoFrame 是明確共享的,所以這 2 實例將反射相同幀。

QVideoFrame:: QVideoFrame ( QVideoFrame && other )

Constructs a QVideoFrame by moving from other .

QVideoFrame:: ~QVideoFrame ()

銷毀視頻幀。

uchar *QVideoFrame:: bits ( int plane )

返迴指針指嚮幀數據緩衝的開始為 plane .

此值纔有效當幀數據為 mapped .

憑藉此指針訪問數據做齣的改變 (當采用寫入訪問映射時) 隻保證有持久化當 unmap () 被調用和當緩衝已被映射以供寫入。

另請參閱 map (), mappedBytes (), bytesPerLine (),和 planeCount ().

const uchar *QVideoFrame:: bits ( int plane ) const

返迴指針指嚮幀數據緩衝的開始為 plane .

此值纔有效當幀數據為 mapped .

若緩衝未采用讀取訪問被映射,此緩衝的內容將被初始為未被初始化。

另請參閱 map (), mappedBytes (), bytesPerLine (),和 planeCount ().

int QVideoFrame:: bytesPerLine ( int plane ) const

Returns the number of bytes in a scan line of a plane .

此值纔有效當幀數據為 mapped .

另請參閱 bits (), map (), mappedBytes (),和 planeCount ().

qint64 QVideoFrame:: endTime () const

返迴要顯示的呈現時間 (以微秒為單位),當幀應停止時。

無效時間錶示為 -1。

另請參閱 setEndTime ().

QVideoFrame::HandleType QVideoFrame:: handleType () const

返迴視頻幀的句柄類型。

The handle type could either be NoHandle , meaning that the frame is memory based, or a RHI texture.

int QVideoFrame:: height () const

返迴視頻幀的高度。

bool QVideoFrame:: isMapped () const

標識目前是否把視頻幀內容,映射到係統內存。

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 .

bool QVideoFrame:: isReadable () const

標識視頻幀映射內容,是否是從幀讀取當映射時。

這是方便校驗函數若 MapMode 包含 QVideoFrame::WriteOnly 標誌。

返迴 true 若從視頻幀讀取映射內存內容,和 false 否則。

另請參閱 mapMode () 和 QVideoFrame::MapMode .

bool QVideoFrame:: isValid () const

標識視頻幀是否有效。

無效幀沒有關聯它的視頻緩衝。

返迴 true 若幀有效,和 false 若幀無效。

bool QVideoFrame:: isWritable () const

標識視頻幀的映射內容是否會持久化,當取消幀映射時。

這是方便校驗函數若 MapMode 包含 QVideoFrame::WriteOnly 標誌。

返迴 true 若將更新視頻幀當取消映射時,否則返迴 false。

注意: 更改以隻讀方式映射幀數據的結果未定義。從屬緩衝實現,改變可能持久化,或更糟更改共享緩衝。

另請參閱 mapMode () 和 QVideoFrame::MapMode .

bool QVideoFrame:: map ( QVideoFrame::MapMode mode )

把視頻幀的內容映射到係統 (CPU 可尋址) 內存。

在某些情況下,視頻幀數據可能存儲在視頻內存 (或其它不可訪問內存) 中,因此有必要映射幀在訪問像素數據前。這可能涉及圍繞內容的拷貝,所以,應避免映射和取消映射 (除非要求)。

映射 mode 指示映射內存內容是否應讀取自和/或寫入幀。若映射模式包括 QVideoFrame::ReadOnly 標誌將采用視頻幀內容填充映射內存當初始映射時。若映射模式包括 QVideoFrame::WriteOnly 標誌可能將修改映射內存內容寫迴到幀當取消映射時。

當映射時,可以直接訪問視頻幀內容透過指針返迴通過 bits () 函數。

當訪問數據不再需要時,確保調用 unmap () 函數以釋放映射內存且可能更新視頻幀內容。

若已以隻讀方式映射視頻幀,則以隻讀方式多次映射 (且取消映射它相應次數) 是準許的。在所有其它情況下,有必要先取消幀映射,在第 2 次映射前。

注意: 由於隻讀寫入映射內存未定義,且可能導緻共享數據改變 (或崩潰)。

返迴 true 若映射幀到內存按給定 mode 和 false 否則。

另請參閱 unmap (), mapMode (),和 bits ().

QVideoFrame::MapMode QVideoFrame:: mapMode () const

返迴將視頻幀映射到係統內存中的模式。

另請參閱 map () 和 QVideoFrame::MapMode .

int QVideoFrame:: mappedBytes ( int plane ) const

Returns the number of bytes occupied by plane plane of the mapped frame data.

此值纔有效當幀數據為 mapped .

另請參閱 map ().

bool QVideoFrame:: mirrored () const

Returns whether the frame should be mirrored before displaying.

另請參閱 setMirrored ().

void QVideoFrame:: paint ( QPainter * painter , const QRectF & rect , const QVideoFrame::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.

注意: that rendering will usually happen without hardware acceleration when using this method.

QVideoFrameFormat::PixelFormat QVideoFrame:: pixelFormat () const

Returns the pixel format of this video frame.

int QVideoFrame:: planeCount () const

返迴視頻幀中的平麵數。

另請參閱 map ().

QVideoFrame::RotationAngle QVideoFrame:: rotationAngle () const

Returns the angle the frame should be rotated clockwise before displaying.

另請參閱 setRotationAngle ().

void QVideoFrame:: setEndTime ( qint64 time )

設置呈現 time (以微秒為單位) 當幀應停止顯示時。

無效時間錶示為 -1。

另請參閱 endTime ().

void QVideoFrame:: setMirrored ( bool mirrored )

設置 mirrored flag for the frame.

另請參閱 mirrored ().

void QVideoFrame:: setRotationAngle ( QVideoFrame::RotationAngle angle )

設置 angle the frame should be rotated clockwise before displaying.

另請參閱 rotationAngle ().

void QVideoFrame:: setStartTime ( qint64 time )

設置呈現 time (以微秒為單位) 當幀應該被初始顯示時。

無效時間錶示為 -1。

另請參閱 startTime ().

void QVideoFrame:: setSubtitleText (const QString & text )

Sets the subtitle text that should be rendered together with this video frame to text .

另請參閱 subtitleText ().

QSize QVideoFrame:: size () const

返迴視頻幀尺度。

qint64 QVideoFrame:: startTime () const

返迴呈現時間 (以微秒為單位) 當幀應該被顯示時。

無效時間錶示為 -1。

另請參閱 setStartTime ().

QString QVideoFrame:: subtitleText () const

Returns the subtitle text that should be rendered together with this video frame.

另請參閱 setSubtitleText ().

QVideoFrameFormat QVideoFrame:: surfaceFormat () const

Returns the surface format of this video frame.

void QVideoFrame:: swap ( QVideoFrame & other )

Swaps the current video frame with other .

QImage QVideoFrame:: toImage () const

基於像素格式將當前視頻幀轉換成圖像。

void QVideoFrame:: unmap ()

釋放內存映射通過 map () 函數。

MapMode 包括 QVideoFrame::WriteOnly 標誌,則這會把映射內存當前內容堅持到視頻幀。

unmap() 不應被調用,若 map () 函數失敗。

另請參閱 map ().

int QVideoFrame:: width () const

返迴視頻幀的寬度。

bool QVideoFrame:: operator!= (const QVideoFrame & other ) const

返迴 true 若此 QVideoFrame and other 不反射相同幀。

QVideoFrame &QVideoFrame:: operator= ( QVideoFrame && other )

移動 other 到此 QVideoFrame .

QVideoFrame &QVideoFrame:: operator= (const QVideoFrame & other )

賦值內容對於 other 到此視頻幀。由於 QVideoFrame 是明確共享的,這 2 實例將反射相同幀。

bool QVideoFrame:: operator== (const QVideoFrame & other ) const

返迴 true 若此 QVideoFrame and other 反射相同幀。