手机支持的最低分辨率:
1.直接获取
CamcorderProfile profile=CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
2.按时间流逝,质量变化情况来
CamcorderProfile profile=CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_LOW);
3.按高帧数下的质量来
CamcorderProfile profile=CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH_SPEED_LOW);
手机支持的最高分辨率:
1.直接获取
CamcorderProfile profile=CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
2.按时间流逝,质量变化情况来
CamcorderProfile profile=CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
3.按高帧数下的质量来
CamcorderProfile profile=CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH_SPEED_HIGH);
/**
* Retrieves the
* predefined camcorder profile settings for camcorder applications.
* These settings are read-only.
*
* The compressed output from a recording session with a given
* CamcorderProfile contains two tracks: one for audio and one for video.
*
*
Each profile specifies the following set of parameters:
*
* - The file output format
*
- Video codec format
*
- Video bit rate in bits per second
*
- Video frame rate in frames per second
*
- Video frame width and height,
*
- Audio codec format
*
- Audio bit rate in bits per second,
*
- Audio sample rate
*
- Number of audio channels for recording.
*
*/
意思呢就是手机里已经有预先定义好的配置信息,你可以直接拿来用(当然,也可以自己设置)。
public int fileFormat;
public int videoCodec;
public int videoBitRate;
public int videoFrameRate;
public int videoFrameWidth;
public int videoFrameHeight;
public int audioCodec;
public int audioBitRate;
public int audioSampleRate;
public int audioChannels
当然,以上是预先定义好的配文件里指定了的属性,未指定的属性还有:
public int duration;//在会话终止之前的默认记录持续时间(以秒为单位),不知道可不可以理解为录像的最大持续时间
public int quality;//分辨率
private CamcorderProfile(int duration,
int quality,
int fileFormat,
int videoCodec,
int videoBitRate,
int videoFrameRate,
int videoWidth,
int videoHeight,
int audioCodec,
int audioBitRate,
int audioSampleRate,
int audioChannels) {
this.duration = duration;
this.quality = quality;
this.fileFormat = fileFormat;
this.videoCodec = videoCodec;
this.videoBitRate = videoBitRate;
this.videoFrameRate = videoFrameRate;
this.videoFrameWidth = videoWidth;
this.videoFrameHeight = videoHeight;
this.audioCodec = audioCodec;
this.audioBitRate = audioBitRate;
this.audioSampleRate = audioSampleRate;
this.audioChannels = audioChannels;
}
这就是自己设置属性了,虽然是private方法,但是可以用反射啊。
public static CamcorderProfile get(int quality) {
int numberOfCameras = Camera.getNumberOfCameras();
CameraInfo cameraInfo = new CameraInfo();
for (int i = 0; i < numberOfCameras; i++) {
Camera.getCameraInfo(i, cameraInfo);
if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
return get(i, quality);
}
}
return null;
}
第二个函数需传入一个cameraID和分辨率,对你传进来的分辨率变量进行大小判定,只要没超过大小边界就返回调用方法放回
一个实例对象,否则报错
public static CamcorderProfile get(int cameraId, int quality) {
if (!((quality >= QUALITY_LIST_START &&
quality <= QUALITY_LIST_END) ||
(quality >= QUALITY_TIME_LAPSE_LIST_START &&
quality <= QUALITY_TIME_LAPSE_LIST_END) ||
(quality >= QUALITY_HIGH_SPEED_LIST_START &&
quality <= QUALITY_HIGH_SPEED_LIST_END))) {
String errMessage = "Unsupported quality level: " + quality;
throw new IllegalArgumentException(errMessage);
}
return native_get_camcorder_profile(cameraId, quality);
}
那么,大小边界是什么呢?静态方法里调用的类变量只能是静态变量。静态变量,对了,这个类里面有没有已经定义好的属性
然后对外提供呢?答案是有的
public static final int QUALITY_LOW = 0;
public static final int QUALITY_HIGH = 1;
public static final int QUALITY_QCIF = 2;
public static final int QUALITY_CIF = 3;
public static final int QUALITY_480P = 4;
public static final int QUALITY_720P = 5;
public static final int QUALITY_1080P = 6;
public static final int QUALITY_QVGA = 7;
public static final int QUALITY_2160P = 8;
// Start and end of quality list
private static final int QUALITY_LIST_START = QUALITY_LOW;
private static final int QUALITY_LIST_END = QUALITY_2160P;
public static final int QUALITY_TIME_LAPSE_LOW = 1000;
public static final int QUALITY_TIME_LAPSE_HIGH = 1001;
public static final int QUALITY_TIME_LAPSE_QCIF = 1002;
public static final int QUALITY_TIME_LAPSE_CIF = 1003;
public static final int QUALITY_TIME_LAPSE_480P = 1004;
public static final int QUALITY_TIME_LAPSE_720P = 1005;
public static final int QUALITY_TIME_LAPSE_1080P = 1006;
public static final int QUALITY_TIME_LAPSE_QVGA = 1007;
public static final int QUALITY_TIME_LAPSE_2160P = 1008;
// Start and end of timelapse quality list
private static final int QUALITY_TIME_LAPSE_LIST_START = QUALITY_TIME_LAPSE_LOW;
private static final int QUALITY_TIME_LAPSE_LIST_END = QUALITY_TIME_LAPSE_2160P;
public static final int QUALITY_HIGH_SPEED_LOW = 2000;
public static final int QUALITY_HIGH_SPEED_HIGH = 2001;
public static final int QUALITY_HIGH_SPEED_480P = 2002;
public static final int QUALITY_HIGH_SPEED_720P = 2003;
public static final int QUALITY_HIGH_SPEED_1080P = 2004;
public static final int QUALITY_HIGH_SPEED_2160P = 2005;
// Start and end of high speed quality list
private static final int QUALITY_HIGH_SPEED_LIST_START = QUALITY_HIGH_SPEED_LOW;
private static final int QUALITY_HIGH_SPEED_LIST_END = QUALITY_HIGH_SPEED_2160P;
哇,原来上面的大小是边界是这个意思啊,原来开头的三种不同的三种获取方式是这样的,当然最常见的还是第一种直接获取
boolean hasProfile(int quality) //当前的摄像头是否有此分辨率下的配置文件(即是否支持此分辨率)
boolean hasProfile(int cameraId, int quality) //指定的摄像头是否有此分辨率下的配置文件(即是否支持此分辨率)
及获取实例的原生方法
static {
System.loadLibrary("media_jni");
native_init();
}
private static native final void native_init();
private static native final CamcorderProfile native_get_camcorder_profile(
int cameraId, int quality);
private static native final boolean native_has_camcorder_profile(
int cameraId, int quality);有兴趣的可以继续深入学习
//最后不妨猜测下,底层的运行方式:
//以一个800W像素和1300W像素的摄像头为例,不妨设对480P、720P、1080P、2160P的支持
//分别为:true/true/false/false,true/true/true/false,当对1300W的摄像头请求2160P支持时,hasProfile(2160P)
//,发现并没有配置文件返回false。但是如果get(2160P)的话,发现没有这么高分辨的配置文件,所以向下兼容,会返回
//的1080P的配置文件,始终会返回一个最大的值
//以上只列出了大部分的信息,还有些许不常见的注意事项请看源码。
//另外Camera类已经被@Deprecated,受到影响不知道谷歌以后会不会修改CamcorderProfile这个类