Exporting Video Encoding Statistics

Stay organized with collections Save and categorize content based on your preferences.

Starting with Android 13, app clients can request the video encoder to export encoding statistics for each encoded video frame. With the statistics obtained from the video encoder, apps can optimize their video encoding tasks such as multipass encoding and frame preprocessing prior to encoding.

To export video encoding statistics, SoC vendors must change the video encoder driver as described in Updates to the video encoder driver.

Video encoding statistics data

With Android 13, the video encoder exports statistics data as shown in the following table.

Name of encoder statistics Description
Average block QP per frame The average of all block QPs in the video frame that are encoded into the bitstream
Picture type Type I or P or B

Developers can retrieve statistics information for each frame by using the MediaFormat developer class.

Updates to the video encoder driver

To support the export of video encoding statistics, SoC vendors must change the video encoder driver. The following keys are added in the Codec 2.0 base in Android 13:

  • KEY_VIDEO_QP_AVERAGE describes the per-frame average block QP.

    The following rules apply to the implementation of the KEY_VIDEO_QP_AVERAGE key:

    • The SoC encoder must round the average of the block QPs to the nearest integer before emitting to Codec 2.0.

    • The average value is computed only from a luma plane.

    • The SoC encoder must return INT_MAX if all the blocks in the current frame are in the skipped mode. This condition occurs when no coefficients are encoded and no significant QP info is encoded in the frame.

  • KEY_PICTURE_TYPE describes the picture type of the encoded frame as PICTURE_TYPE_I, PICTURE_TYPE_P, PICTURE_TYPE_B, or PICTURE_TYPE_UNKNOWN.

  • KEY_VIDEO_ENCODING_STATISTICS_LEVEL describes the level of encoding statistics information emitted from video encoder, as follows:

See VideoEncodingStatisticsTest for a reference implementation.


Run the VideoEncodingStatisticsTest CTS test to validate that the average QP part of the video encoding statistics works correctly: CTS runs two encodings of the same input video, one with a higher bitrate, and another with a lower bitrate. CTS then compares the two exported average QP values from the two encodings. If the average QP from the encoding with the lower bitrate is higher than the average QP from the encoding with the higher bitrate, CTS passes.

To validate turning off the exporting video encoding statistics feature when enabled, use the VIDEO_ENCODING_STATISTICS_LEVEL_NONE key as follows: