Open In App

Exporting Video Encoding Statistics in Android 13

Last Updated : 07 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Video encoding has been a long-time feature present in the Android system, it only keeps getting better with newer hardware and now, it even goes further in Android 13. This update brings us, even better video encoding and a new feature of exporting the video encoding statistics. In this article, we will look at how to implement this, and what could be challenges we might face while implementing this. By the end of this article, you will be able to successfully export the statistics and then cross-work with them, so without further ado, let’s dive deep into this.

Android 13 Introduces Video Encoding Statistics

App clients can ask the video encoder to export encoding information for each encoded video frame as of Android version 13. Apps can optimize their video encodings activities, such as multipass encoding and frame preprocessing before encoding, with the statistics obtained from the video encoder. SoC vendors must update the video encoder driver as outlined in Updates to the video encoder driver in order to export video encoding statistics.

Use Cases of Video Encoding Statistics:

Various apps we use every day have a great usage scope of this API when they implement it, if you own an editing app, you can now tell the user about the granular changes to the file types when the codecs change, it could also help by:

  1. Providing an extra layer of information to tell users when they use the app
  2. Determining the estimated time to complete more properly than ever.
  3. Predetermining if the project will comply and export fully on the running hardware.

What all Data Can Be Exported:

With this API, the developer can reference two values as of now, as this API has just been released in Android 13, there would be further improvements in the future to make it even more feature rich.

The current methods are:

Encoder Statistic

Description

Type of Picture Presented PAL, AUTO, or Other Type I and II
Number of frames working at one-time The average of all the block QPs that are encoded into the bitstream for the video frame

Adding Video Drivers to Encoding

SoC suppliers must update the video encoder driver to facilitate the export of video encoding statistics. In Android 13, the following keys are added to the Codec 2.0 base:

  1. The per-frame average block QP is described by the key KEY_VIDEO_QP_AVERAGE.
  2. The KEY_VIDEO_QP_AVERAGE key must be implemented in accordance with the guidelines listed below:
  3. Before broadcasting to Codec 2.0, the SoC encoder must round the average of the block QPs to the nearest integer.
  4. Only a luma plane is used to determine the average value.

GeekTip: If every block in the current frame is in the skipped mode, the SoC encoder must output INT MAX. This situation arises when the frame has no important QP information and no coefficients.

Values that Determine Video Encoding

Prior to Android 13, there was a lot of chaos, as there were different values that were proposed by using different functions for Video Encoding, but now we have a safe, dedicated method to work and analyze the proportion. We would need to understand that the following functions are available for us to use now:

  1. Using floor(), the average value is rounded down to an integer value.
  2. This is a portion of the export function for the video “Encoding Statistics.”
  3. For a video frame, the video encoder emits this value.

Implementing the new standards in applications

All of this knowledge is determined by a really simple API, which we can use in applications to help determine the exported video statistics, there would be a huge chunk of apps that would work with this setup. Use the code below to store the video statistics in an integer, and then you can continue to work on it to get the desired result:

Java




// Add this to a main activity where the exporting actually
// happens Geeks for Geeks
gfgFormat.setInteger(
    MediaFormat.KEY_VIDEO_ENCODING_STATISTICS_LEVEL,
    MediaFormat.VIDEO_ENCODING_STATISTICS_LEVEL_NONE);


Verifying if the Addition Works

To confirm that the average QP portion of the video encoding statistics functions properly, run the VideoEncodingStatisticsTest CTS test: The same input video is encoded twice by CTS, once at a higher bitrate and once at a lower bitrate. The two exported average QP values from the two encodings are then compared by CTS. CTS passes if the average QP from the lower bitrate encoding is higher than the average QP from the higher bitrate encoding. Use the VIDEO_ENCODING_STATISTICS LEVEL_NONE flag to confirm disabling the exporting of video encoding statistics when it is enabled, like in the example shown above.

Conclusion

Hope this article helped you understand how to add the Video Encoding Stats, and helped you learn that for all formats that are listed as unsupported, compatible media transcoding is enabled; for all formats listed as supported, it is disabled. The platform chooses whether to transcode for any other formats that have not been stated. For all undeclared formats, transcoding is disabled in Android 13. Future formats may cause this behavior to alter.


Similar Reads

How to Integrate Facebook Audience Network (FAN) Rewarded Video Ads in Android?
In order to earn money from the Android app or game, there are many ways such as in-App Purchases, Sponsorship, Advertisements, and many more. But there is another popular method to earn money from the Android app is by integrating a third party advertisement e.g known as Facebook Audience Network (FAN). Facebook Audience Network is designed to hel
6 min read
How to Integrate Google Admob Rewarded Video Ads in Android?
In order to earn money from the Android app or game, there are many ways such as in-App Purchases, Sponsorship, Advertisements, and many more. But there is another popular method to earn money from the Android app is by integrating an advertisement e.g known as Google AdMob. Google AdMob is designed with developers in mind, AdMob helps to earn more
7 min read
How to Create Video Player and Downloader App in Android?
In this article, we will walk you through the process of creating a simple video player and downloader app in Android using Kotlin and Android Studio. In this project, we will use firebase to store videos and generate URLs. A sample video is given below to get an idea about what we are going to do in this article. [video mp4="https://media.geeksfor
3 min read
How to Create a Dynamic Video Player in Android with Firebase Realtime Database?
Most of the apps use the video player to display so many videos inside their application. So for playing the video the app plays the video from its video URL. But what if we want to update that video on a real-time basis. So, in that case, we have to update our database and then later on we have to update our APK. So this is not an efficient way to
8 min read
How to Build a Video Calling Android App with Jitsi Meet SDK?
Video Calling becomes a most demanding feature in many social media apps like WhatsApp, Instagram, Facebook, etc. Not only this but also there are some other applications available for providing only this feature to connect people all over the world with each other like Duo. Hence, this gives an idea to us about the importance of video calling. So
6 min read
How to Play YouTube Video in Android Using YouTube API?
YouTube Android Player API lets you play any YouTube video or playlist inside your app that too without leaving your app. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using both Java and Kotlin language. [video mp4="https://media.geeksforgeeks.org/wp-con
4 min read
Eye Detecting Video Player in Android
In this article, we are going to learn that how we can make an eye detecting video player and use third-party libraries in our android application. If you are a beginner in android development then by making this application you will boost your confidence and learn some interesting and new. What we are going to build in this article? In this applic
4 min read
How to Upload a Video in Firebase Database using Android Studio?
Firebase is a mobile and web application development platform. It provides services that a web application or mobile application might require. Firebase provides secure file uploads and downloads for the Firebase application. This article explains how to build an Android application with the ability to select a video from the mobile gallery and upl
3 min read
How to Play Video from URL in Android?
In this article, you will see how to play a video from URL on Android. For showing the video in our android application we will use the VideoView widget. The VideoView widget is capable of playing media files, and the formats supported by the VideoView are 3gp and MP4. By using VideoView you can play media files from the local storage and also from
3 min read
How Voice And Video Call Works in Android?
Voice over Internet Protocol (VoIP) is a common technology for voice and video communication over the internet. This Geeks for Geeks article will go through how voice and video calls function on a high level. We all utilize audio and video on services such as WhatsApp, Skype, Messenger, Facebook, and so on. Essentially, both voice and video calls a
4 min read