QVideoFrame 類

The QVideoFrame class represents a frame of video data. 更多...

頭: #include <QVideoFrame>
qmake: QT += multimedia

公共類型

enum FieldType { ProgressiveFrame, TopField, BottomField, InterlacedFrame }
enum PixelFormat { Format_Invalid, Format_ARGB32, Format_ARGB32_Premultiplied, Format_RGB32, ..., Format_User }

公共函數

QVideoFrame ()
QVideoFrame (QAbstractVideoBuffer * buffer , const QSize & size , QVideoFrame::PixelFormat format )
QVideoFrame (int bytes , const QSize & size , int bytesPerLine , QVideoFrame::PixelFormat format )
QVideoFrame (const QImage & image )
QVideoFrame (const QVideoFrame & other )
~QVideoFrame ()
QVariantMap availableMetaData () const
uchar * bits ()
uchar * bits (int plane )
const uchar * bits () const
const uchar * bits (int plane ) const
int bytesPerLine () const
int bytesPerLine (int plane ) const
qint64 endTime () const
QVideoFrame::FieldType fieldType () const
QVariant handle () const
QAbstractVideoBuffer::HandleType handleType () const
int height () const
bool isMapped () const
bool isReadable () const
bool isValid () const
bool isWritable () const
bool map (QAbstractVideoBuffer::MapMode mode )
QAbstractVideoBuffer::MapMode mapMode () const
int mappedBytes () const
QVariant metaData (const QString & key ) const
QVideoFrame::PixelFormat pixelFormat () const
int planeCount () const
void setEndTime (qint64 time )
void setFieldType (QVideoFrame::FieldType field )
void setMetaData (const QString & key , const QVariant & value )
void setStartTime (qint64 time )
QSize size () const
qint64 startTime () const
void unmap ()
int width () const
bool operator!= (const QVideoFrame & other ) const
QVideoFrame & operator= (const QVideoFrame & other )
bool operator== (const QVideoFrame & other ) const

靜態公共成員

QImage::Format imageFormatFromPixelFormat (QVideoFrame::PixelFormat format )
QVideoFrame::PixelFormat pixelFormatFromImageFormat (QImage::Format format )

詳細描述

The QVideoFrame class represents a frame of video data.

A QVideoFrame encapsulates the pixel data of a video frame, and information about the frame.

視頻幀可以來自幾個地方 - 解碼的 media camera ,或以編程方式生成。在這些幀中描述像素的方式可能有很大不同,且一些像素格式以易用性為代價提供更大壓縮機會。

視頻幀的像素內容映射到內存可以使用 map () 函數。當映射時,視頻數據的訪問可以使用 bits () 函數,返迴緩衝指針。此緩衝總大小的給定是通過 mappedBytes () 函數,和每行大小的給定是通過 bytesPerLine ()。返迴值對於 handle () 函數也可以使用內部緩衝的本地 API 來訪問幀數據 (例如:OpenGL 紋理句柄)。

視頻幀也可以擁有關聯它的時間戳信息。這些時間戳可以用於實現的 QAbstractVideoSurface 以確定何時開始和停止顯示幀,但並非所有錶麵都可能遵守此設置。

The video pixel data in a QVideoFrame is encapsulated in a QAbstractVideoBuffer QVideoFrame may be constructed from any buffer type by subclassing the QAbstractVideoBuffer 類。

注意: Since video frames can be expensive to copy, QVideoFrame is explicitly shared, so any change made to a video frame will also apply to any copies.

成員類型文檔編製

enum QVideoFrame:: FieldType

指定隔行掃描視頻幀所屬的字段。

常量 描述
QVideoFrame::ProgressiveFrame 0 幀非隔行掃描。
QVideoFrame::TopField 1 幀包含 top 字段。
QVideoFrame::BottomField 2 框架包含 bottom 字段。
QVideoFrame::InterlacedFrame 3 幀包含閤並的 top 和 bottom 字段。

enum QVideoFrame:: PixelFormat

枚舉視頻數據類型。

常量 描述
QVideoFrame::Format_Invalid 0 幀無效。
QVideoFrame::Format_ARGB32 1 使用 32 位 ARGB 格式 (0xAARRGGBB) 存儲幀。這相當於 QImage::Format_ARGB32 .
QVideoFrame::Format_ARGB32_Premultiplied 2 使用預乘 32 位 ARGB 格式 (0xAARRGGBB) 存儲幀。這相當於 QImage::Format_ARGB32_Premultiplied .
QVideoFrame::Format_RGB32 3 使用 32 位 RGB 格式 (0xffRRGGBB) 存儲幀。這相當於 QImage::Format_RGB32
QVideoFrame::Format_RGB24 4 The frame is stored using a 24-bit RGB format (8-8-8). This is equivalent to QImage::Format_RGB888
QVideoFrame::Format_RGB565 5 The frame is stored using a 16-bit RGB format (5-6-5). This is equivalent to QImage::Format_RGB16 .
QVideoFrame::Format_RGB555 6 The frame is stored using a 16-bit RGB format (5-5-5). This is equivalent to QImage::Format_RGB555 .
QVideoFrame::Format_ARGB8565_Premultiplied 7 The frame is stored using a 24-bit premultiplied ARGB format (8-5-6-5).
QVideoFrame::Format_BGRA32 8 The frame is stored using a 32-bit BGRA format (0xBBGGRRAA).
QVideoFrame::Format_BGRA32_Premultiplied 9 The frame is stored using a premultiplied 32bit BGRA format.
QVideoFrame::Format_BGR32 10 The frame is stored using a 32-bit BGR format (0xBBGGRRff).
QVideoFrame::Format_BGR24 11 The frame is stored using a 24-bit BGR format (0xBBGGRR).
QVideoFrame::Format_BGR565 12 幀使用 16 位 BGR 格式 (5-6-5) 存儲。
QVideoFrame::Format_BGR555 13 幀使用 16 位 BGR 格式 (5-5-5) 存儲。
QVideoFrame::Format_BGRA5658_Premultiplied 14 The frame is stored using a 24-bit premultiplied BGRA format (5-6-5-8).
QVideoFrame::Format_AYUV444 15 The frame is stored using a packed 32-bit AYUV format (0xAAYYUUVV).
QVideoFrame::Format_AYUV444_Premultiplied 16 The frame is stored using a packed premultiplied 32-bit AYUV format (0xAAYYUUVV).
QVideoFrame::Format_YUV444 17 The frame is stored using a 24-bit packed YUV format (8-8-8).
QVideoFrame::Format_YUV420P 18 The frame is stored using an 8-bit per component planar YUV format with the U and V planes horizontally and vertically sub-sampled, i.e. the height and width of the U and V planes are half that of the Y plane.
QVideoFrame::Format_YV12 19 The frame is stored using an 8-bit per component planar YVU format with the V and U planes horizontally and vertically sub-sampled, i.e. the height and width of the V and U planes are half that of the Y plane.
QVideoFrame::Format_UYVY 20 The frame is stored using an 8-bit per component packed YUV format with the U and V planes horizontally sub-sampled (U-Y-V-Y), i.e. two horizontally adjacent pixels are stored as a 32-bit macropixel which has a Y value for each pixel and common U and V values.
QVideoFrame::Format_YUYV 21 The frame is stored using an 8-bit per component packed YUV format with the U and V planes horizontally sub-sampled (Y-U-Y-V), i.e. two horizontally adjacent pixels are stored as a 32-bit macropixel which has a Y value for each pixel and common U and V values.
QVideoFrame::Format_NV12 22 The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y) followed by a horizontally and vertically sub-sampled, packed UV plane (U-V).
QVideoFrame::Format_NV21 23 The frame is stored using an 8-bit per component semi-planar YUV format with a Y plane (Y) followed by a horizontally and vertically sub-sampled, packed VU plane (V-U).
QVideoFrame::Format_IMC1 24 The frame is stored using an 8-bit per component planar YUV format with the U and V planes horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except that the bytes per line of the U and V planes are padded out to the same stride as the Y plane.
QVideoFrame::Format_IMC2 25 The frame is stored using an 8-bit per component planar YUV format with the U and V planes horizontally and vertically sub-sampled. This is similar to the Format_YUV420P type, except that the lines of the U and V planes are interleaved, i.e. each line of U data is followed by a line of V data creating a single line of the same stride as the Y data.
QVideoFrame::Format_IMC3 26 The frame is stored using an 8-bit per component planar YVU format with the V and U planes horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that the bytes per line of the V and U planes are padded out to the same stride as the Y plane.
QVideoFrame::Format_IMC4 27 The frame is stored using an 8-bit per component planar YVU format with the V and U planes horizontally and vertically sub-sampled. This is similar to the Format_YV12 type, except that the lines of the V and U planes are interleaved, i.e. each line of V data is followed by a line of U data creating a single line of the same stride as the Y data.
QVideoFrame::Format_Y8 28 使用 8 位灰度格式存儲幀。
QVideoFrame::Format_Y16 29 使用 16 位綫性灰度格式存儲幀。小端在前。
QVideoFrame::Format_Jpeg 30 以壓縮的 JPEG 格式存儲幀。
QVideoFrame::Format_CameraRaw 31 使用特定設備攝像頭原生格式存儲幀。
QVideoFrame::Format_AdobeDng 32 使用原生 Adobe DNG (數字負片) 格式存儲幀。
QVideoFrame::Format_User 1000 用戶定義像素格式的起始值。

成員函數文檔編製

QVideoFrame:: QVideoFrame ()

構造 null 視頻幀。

QVideoFrame:: QVideoFrame ( QAbstractVideoBuffer * buffer , const QSize & size , QVideoFrame::PixelFormat format )

構造視頻幀從 buffer 采用給定像素 format and size (以像素為單位)。

注意: 這不會遞增視頻緩衝的引用計數。

QVideoFrame:: QVideoFrame ( int bytes , const QSize & size , int bytesPerLine , QVideoFrame::PixelFormat format )

構造視頻幀采用給定像素 format and size (以像素為單位)。

The bytesPerLine (步幅) 是每掃描行的長度 (以字節為單位),和 bytes 是必須為幀分配的總字節數。

QVideoFrame:: QVideoFrame (const QImage & image )

構造視頻幀從 image .

注意: 這會構造無效視頻幀,若不存在等價圖像格式的幀類型。

另請參閱 pixelFormatFromImageFormat ().

QVideoFrame:: QVideoFrame (const QVideoFrame & other )

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

QVideoFrame:: ~QVideoFrame ()

銷毀視頻幀。

QVariantMap QVideoFrame:: availableMetaData () const

返迴關聯此幀的任何額外元數據。

uchar *QVideoFrame:: bits ()

返迴指嚮幀數據緩衝起始的指針。

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

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

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

uchar *QVideoFrame:: bits ( int plane )

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

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

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

該函數在 Qt 5.4 引入。

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

const uchar *QVideoFrame:: bits () const

返迴指嚮幀數據緩衝起始的指針。

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

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

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

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

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

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

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

該函數在 Qt 5.4 引入。

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

int QVideoFrame:: bytesPerLine () const

返迴掃描行字節數。

注意: For planar formats this is the bytes per line of the first plane only. The bytes per line of subsequent planes should be calculated as per the frame 像素格式 .

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

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

int QVideoFrame:: bytesPerLine ( int plane ) const

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

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

該函數在 Qt 5.4 引入。

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

qint64 QVideoFrame:: endTime () const

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

無效時間錶示為 -1。

另請參閱 setEndTime ().

QVideoFrame::FieldType QVideoFrame:: fieldType () const

返迴隔行掃描視頻幀所屬的字段。

若不是隔行掃描視頻,這會返迴 WholeFrame。

另請參閱 setFieldType ().

QVariant QVideoFrame:: handle () const

返迴視頻幀緩衝的特定類型句柄。

對於 OpenGL 紋理,這將是紋理 ID。

另請參閱 QAbstractVideoBuffer::handle ().

QAbstractVideoBuffer::HandleType QVideoFrame:: handleType () const

返迴視頻幀的句柄類型。

int QVideoFrame:: height () const

返迴視頻幀的高度。

[static] QImage::Format QVideoFrame:: imageFormatFromPixelFormat ( QVideoFrame::PixelFormat format )

返迴圖像格式等效視頻幀像素 format 。若沒有等效格式 QImage::Format_Invalid 被返迴取而代之。

注意: 一般而言 QImage 沒有 YUV 格式。

bool QVideoFrame:: isMapped () const

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

This is a convenience function which checks that the MapMode of the frame is not equal to QAbstractVideoBuffer::NotMapped .

Returns true if the contents of the video frame are mapped to system memory, and false otherwise.

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

bool QVideoFrame:: isReadable () const

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

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

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

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

bool QVideoFrame:: isValid () const

標識視頻幀是否有效。

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

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

bool QVideoFrame:: isWritable () const

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

QAbstractVideoBuffer::MapMode QVideoFrame:: mapMode () const

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

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

int QVideoFrame:: mappedBytes () const

返迴由映射幀數據所占據的字節數。

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

另請參閱 map ().

QVariant QVideoFrame:: metaData (const QString & key ) const

返迴此幀的任何元數據為給定 key .

這可能包括來自攝像頭的幀特定信息,或來自解碼視頻流的字幕。

見相關視頻幀生産者文檔編製,進一步瞭解可用元數據的有關信息。

另請參閱 setMetaData ().

QVideoFrame::PixelFormat QVideoFrame:: pixelFormat () const

返迴視頻幀的顔色格式。

[static] QVideoFrame::PixelFormat QVideoFrame:: pixelFormatFromImageFormat ( QImage::Format format )

返迴視頻像素格式相當於圖像 format 。若不存在等價格式,返迴 QVideoFrame::InvalidType 代替。

注意: 一般而言 QImage 沒有 YUV 格式。

int QVideoFrame:: planeCount () const

返迴視頻幀中的平麵數。

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

該函數在 Qt 5.4 引入。

另請參閱 map ().

void QVideoFrame:: setEndTime ( qint64 time )

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

無效時間錶示為 -1。

另請參閱 endTime ().

void QVideoFrame:: setFieldType ( QVideoFrame::FieldType field )

設置 field 屬於隔行掃描視頻幀。

另請參閱 fieldType ().

void QVideoFrame:: setMetaData (const QString & key , const QVariant & value )

設置元數據為給定 key to value .

value 是 null 變體,將移除此鍵的任何元數據。

視頻幀生産者可能使用這將某些數據與此幀關聯,或讓中間處理器為此幀的消費者添加信息。

另請參閱 metaData ().

void QVideoFrame:: setStartTime ( qint64 time )

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

無效時間錶示為 -1。

另請參閱 startTime ().

QSize QVideoFrame:: size () const

返迴視頻幀尺度。

qint64 QVideoFrame:: startTime () const

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

無效時間錶示為 -1。

另請參閱 setStartTime ().

void QVideoFrame:: unmap ()

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

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

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

另請參閱 map ().

int QVideoFrame:: width () const

返迴視頻幀的寬度。

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

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

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

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

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

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