14

我的应用程序使用 HLS 从服务器流式传输视频,但是当我从服务器请求 HLS 流时,我需要将设备可以处理的最大视频比特率传递给它。在Android API 指南中,它说“设备的可用视频录制配置文件可以用作媒体播放功能的代理”,但是当我尝试检索设备后置摄像头的 videoBitRate 时,它​​总是返回 12Mb/s无论设备如何(Galaxy Nexus、Galaxy Tab Plus 7"、Galaxy Tab 8.9),尽管它们有 3 个不同的 GPU(PowerVR SGX540、Mali-400 MP、Tegra 250 T20)。这是我的代码,我在做什么错误的?

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

如果我在 Galaxy Tab Plus 上试试这个:

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

它返回 True,尽管 QUALITY_HIGH 用于 1080p 录制并且规格说它只能以 720p 录制。

4

1 回答 1

8

看来我已经找到了自己问题的答案。

我没有仔细阅读文档,QUALITY_HIGH 不等于 1080p,它只是指定设备支持的最高质量配置文件的一种方式。因此,根据定义,CamcorderProfile.hasProfile( CamcorderProfile.QUALITY_HIGH )总是正确的。我应该写这样的东西:

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;
}

我的大多数设备仍在报告对 1080p 编码的支持,我对此表示怀疑,但是我在 Sony Experia Tipo(我的低端测试设备)上运行了此代码,它报告的最大编码质量为 480p,videoBitRate 为 720Kb /秒。

正如我所说,我不确定是否每个设备都值得信赖,但我已经看到了从 720Kb/s 到 17Mb/s 的一系列视频比特率和从 480p 到 1080p 的配置文件质量。希望其他人会发现此信息有用。

于 2013-07-16T02:26:46.873 回答