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
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_AVERAGEdescribes the per-frame average block QP.
The following rules apply to the implementation of the
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_MAXif 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_TYPEdescribes the picture type of the encoded frame as
KEY_VIDEO_ENCODING_STATISTICS_LEVELdescribes the level of encoding statistics information emitted from video encoder, as follows:
When the encoder generates no information about encoding statistics, this key is set to
When the encoder generates
KEY_PICTURE_TYPEfor each frame, this key is set to
for a reference implementation.
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: