自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
匯出影片編碼統計資料
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
自 Android 13 起,應用程式用戶端可以要求影片編碼器匯出每個已編碼影片影格的精靈統計資料。應用程式可利用從影片編碼器取得的統計資料,在編碼前最佳化影片編碼工作,例如多重通道編碼和影格預先處理。
如要匯出影片編碼統計資料,SoC 供應商必須變更影片編碼器驅動程式,詳情請參閱「影片編碼器驅動程式的更新」。
影片編碼統計資料
在 Android 13 中,影片編碼器會匯出統計資料,如下表所示。
編碼器統計資料的名稱 |
說明 |
每個影格平均的區塊 QP |
編碼至位元串流的視訊框架中所有區塊 QP 的平均值 |
圖片類型
|
類型 I 或 P 或 B
|
開發人員可以使用 MediaFormat
開發人員類別,擷取每個影格統計資料的資訊。
影片編碼器驅動程式更新
如要支援匯出視訊編碼統計資料,SoC 供應商必須變更視訊編碼器驅動程式。在 Android 13 的 Codec 2.0 基礎中,新增了下列鍵:
如需參考實作方式,請參閱 VideoEncodingStatisticsTest
。
驗證
請執行 VideoEncodingStatisticsTest
CTS 測試,驗證影片編碼統計資料的平均 QP 部分是否正常運作:CTS 會對同一個輸入影片執行兩次編碼,其中一個使用較高的位元率,另一個則使用較低的位元率。接著,CTS 會比較兩種編碼方式中兩個匯出的平均 QP 值。如果較低位元率的編碼作業產生的平均 QP 高於較高位元率的編碼作業產生的平均 QP,則 CTS 會通過。
如要驗證在啟用時關閉匯出影片編碼統計資料功能,請使用 VIDEO_ENCODING_STATISTICS_LEVEL_NONE
鍵,如下所示:
format.setInteger(MediaFormat.KEY_VIDEO_ENCODING_STATISTICS_LEVEL, MediaFormat.VIDEO_ENCODING_STATISTICS_LEVEL_NONE);
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Export video encoding statistics\n\nStarting with Android 13, app clients can request the\nvideo encoder to export encoding statistics for each encoded video frame. With\nthe statistics obtained from the video encoder, apps can optimize their video\nencoding tasks such as multipass encoding and frame preprocessing prior to\nencoding.\n\nTo export video encoding statistics, SoC vendors must change the video encoder\ndriver as described in [Updates to the video encoder driver](#updates-encoder).\n\nVideo encoding statistics data\n------------------------------\n\nWith Android 13, the video encoder exports statistics\ndata as shown in the following table.\n\n| Name of encoder statistics | Description |\n|----------------------------|-------------------------------------------------------------------------------------|\n| Average block QP per frame | The average of all block QPs in the video frame that are encoded into the bitstream |\n| Picture type | Type I or P or B |\n\nDevelopers can retrieve statistics information for each frame by using the\n[`MediaFormat`](https://developer.android.com/reference/android/media/MediaFormat)\ndeveloper class.\n\nUpdates to the video encoder driver\n-----------------------------------\n\nTo support the export of video encoding statistics, SoC vendors must change the\nvideo encoder driver. The following keys are added in the Codec 2.0 base in\nAndroid 13:\n\n- [`KEY_VIDEO_QP_AVERAGE`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/media/java/android/media/MediaFormat.java;drc=5ad6db77423479d027abb791ad3c02da39513a2c;l=1154) describes the per-frame\n average block QP.\n\n The following rules apply to the implementation of the `KEY_VIDEO_QP_AVERAGE`\n key:\n - The SoC encoder must round the average of the block QPs to the nearest\n integer before emitting to Codec 2.0.\n\n - The average value is computed only from a luma plane.\n\n - The SoC encoder must return `INT_MAX` if all the blocks in the current\n frame are in the skipped mode. This condition occurs when no coefficients are\n encoded and no significant QP info is encoded in the frame.\n\n- [`KEY_PICTURE_TYPE`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/media/java/android/media/MediaFormat.java;drc=5ad6db77423479d027abb791ad3c02da39513a2c;l=1163)\n describes the picture type of the encoded frame as [`PICTURE_TYPE_I`](https://developer.android.com/reference/android/media/MediaFormat#PICTURE_TYPE_I),\n [`PICTURE_TYPE_P`](https://developer.android.com/reference/android/media/MediaFormat#PICTURE_TYPE_P),\n [`PICTURE_TYPE_B`](https://developer.android.com/reference/android/media/MediaFormat#PICTURE_TYPE_B),\n or [`PICTURE_TYPE_UNKNOWN`](https://developer.android.com/reference/android/media/MediaFormat#PICTURE_TYPE_UNKNOWN).\n\n- [`KEY_VIDEO_ENCODING_STATISTICS_LEVEL`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/media/java/android/media/MediaFormat.java;drc=5ad6db77423479d027abb791ad3c02da39513a2c;l=1122) describes the level of\n encoding statistics information emitted from video encoder, as follows:\n\n - When the encoder generates no information about encoding statistics,\n this key is set to [`VIDEO_ENCODING_STATISTICS_LEVEL_NONE`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/media/java/android/media/MediaFormat.java;drc=5ad6db77423479d027abb791ad3c02da39513a2c;l=1129).\n\n - When the encoder generates `KEY_VIDEO_QP_AVERAGE` and `KEY_PICTURE_TYPE`\n for each frame, this key is set to [`VIDEO_ENCODING_STATISTICS_LEVEL_1`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/media/java/android/media/MediaFormat.java;drc=5ad6db77423479d027abb791ad3c02da39513a2c;l=1136).\n\nSee [`VideoEncodingStatisticsTest`](https://cs.android.com/android/platform/superproject/+/android-latest-release:cts/tests/tests/media/codec/src/android/media/codec/cts/VideoEncodingStatisticsTest.java;drc=77bafd18279c8d6dad49fd74dac2e369fdc6ba69;l=56)\nfor a reference implementation.\n\nValidation\n----------\n\nRun the [`VideoEncodingStatisticsTest`](https://cs.android.com/android/platform/superproject/+/android-latest-release:cts/tests/tests/media/codec/src/android/media/codec/cts/VideoEncodingStatisticsTest.java;drc=77bafd18279c8d6dad49fd74dac2e369fdc6ba69;l=56)\nCTS test to validate that the average QP part of the video encoding statistics\nworks correctly: CTS runs two encodings of the same input video, one with a\nhigher bitrate, and another with a lower bitrate. CTS then compares the two\nexported average QP values from the two encodings. If the average QP from the encoding\nwith the lower bitrate is higher than the average QP from the encoding with the\nhigher bitrate, CTS passes.\n\nTo validate turning off the exporting video encoding statistics feature when\nenabled, use the `VIDEO_ENCODING_STATISTICS_LEVEL_NONE` key as follows: \n\n format.setInteger(MediaFormat.KEY_VIDEO_ENCODING_STATISTICS_LEVEL, MediaFormat.VIDEO_ENCODING_STATISTICS_LEVEL_NONE);"]]