Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get CamcorderProfile.videoBitRate for an Android device?

Tags:

android

My app uses HLS to stream video from a server, but when I request the HLS stream from the server I need to pass it the max video bitrate the device can handle. In the Android API guides it says that "a device's available video recording profiles can be used as a proxy for media playback capabilities," but when I try to retrieve the videoBitRate for the devices back-facing camera it always comes back as 12Mb/s regardless of the device (Galaxy Nexus, Galaxy Tab Plus 7", Galaxy Tab 8.9), despite the fact that they have 3 different GPUs (PowerVR SGX540, Mali-400 MP, Tegra 250 T20). Here's my code, am I doing something wrong?

CamcorderProfile camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
targetVideoBitRate = camcorderProfile.videoBitRate;

If I try this on the Galaxy Tab Plus:

boolean hasProfile = CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_HIGH);

it returns True, despite the fact that QUALITY_HIGH is for 1080p recording and the specs say it can only record at 720p.

like image 728
Andrew Ogden Avatar asked Feb 01 '13 01:02

Andrew Ogden


1 Answers

It looks like I've found the answer to my own question.

I didn't read the documentation closely enough, QUALITY_HIGH is not equivalent to 1080p it is simply a way of specifying the highest quality profile the device supports. Therefore, by definition, CamcorderProfile.hasProfile( CamcorderProfile.QUALITY_HIGH ) is always true. I should have written something like this:

public enum mVideoQuality { 
    FullHD, HD, SD
}
mVideoQuality mMaxVideoQuality;
int mTargetVideoBitRate;

private void initVideoQuality {
    if ( CamcorderProfile.hasProfile( CamcorderProfile.QUALITY_1080P ) ) {
        mMaxVideoQuality = mVideoQuality.FullHD;
    } else if ( CamcorderProfile.hasProfile( CamcorderProfile.QUALITY_720P ) ) {
        mMaxVideoQuality = mVideoQuality.HD;
    } else {
        mMaxVideoQuality = mVideoQuality.SD;
    }
    CamcorderProfile cProfile = CamcorderProfile.get( CamcorderProfile.QUALITY_HIGH );
    mTargetVideoBitRate = cProfile.videoBitRate;
}

Most of my devices are still reporting support for 1080p encoding, which I'm skeptical of, however I ran this code on a Sony Experia Tipo ( my low end test device ) and it reported a max encode quality of 480p with a videoBitRate of 720Kb/s.

As I said, I'm not sure if every device can be trusted, but I have seen a range of video bitrates from 720Kb/s to 17Mb/s and Profile qualities from 480p - 1080p. Hopefully other people will find this information to be useful.

like image 73
Andrew Ogden Avatar answered Nov 15 '22 21:11

Andrew Ogden