Android 预览分辨率不为';不匹配编解码器分辨率
我正在尝试在设备之间传输视频。我想支持尽可能旧的设备。因此,我开始学习姜饼(API 10)上的Android 预览分辨率不为';不匹配编解码器分辨率,android,android-camera,android-mediacodec,Android,Android Camera,Android Mediacodec,我正在尝试在设备之间传输视频。我想支持尽可能旧的设备。因此,我开始学习姜饼(API 10)上的MediaRecorder类,但它有一些问题。现在,我要转到Jelly Bean(API 16)和MediaCodec 我正在相机的PreviewCallback中将数据传送到编解码器。我必须使用相同的分辨率进行预览和编解码器。但是在我们的一些测试设备上,预览分辨率和编解码器及其分辨率之间没有交叉点 那么,如何在这些设备上捕获视频呢?我知道在MediaCodec中有createInputSurface,
MediaRecorder
类,但它有一些问题。现在,我要转到Jelly Bean(API 16)和MediaCodec
我正在相机的PreviewCallback
中将数据传送到编解码器。我必须使用相同的分辨率进行预览和编解码器。但是在我们的一些测试设备上,预览分辨率和编解码器及其分辨率之间没有交叉点
那么,如何在这些设备上捕获视频呢?我知道在MediaCodec
中有createInputSurface
,但它需要API 18,我必须切断设备,这是无法接受的
那么如何解决呢
查找最佳可能分辨率的代码:
CamcorderProfile bestProfile() {
final int[] profiles;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
profiles = new int[]{CamcorderProfile.QUALITY_HIGH, CamcorderProfile.QUALITY_2160P, CamcorderProfile.QUALITY_1080P, CamcorderProfile.QUALITY_720P, CamcorderProfile.QUALITY_480P, CamcorderProfile.QUALITY_CIF, CamcorderProfile.QUALITY_QCIF, CamcorderProfile.QUALITY_LOW};
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
profiles = new int[]{CamcorderProfile.QUALITY_HIGH, CamcorderProfile.QUALITY_1080P, CamcorderProfile.QUALITY_720P, CamcorderProfile.QUALITY_480P, CamcorderProfile.QUALITY_CIF, CamcorderProfile.QUALITY_QCIF, CamcorderProfile.QUALITY_LOW};
} else {
profiles = new int[]{CamcorderProfile.QUALITY_HIGH, CamcorderProfile.QUALITY_LOW};
}
for (final int p : profiles) {
try {
final CamcorderProfile profile = CamcorderProfile.get(p);
String encoder = EncoderDebugger.debug(this, profile.videoFrameWidth, profile.videoFrameHeight).getEncoderName();
Log.d(String.valueOf(profile.videoFrameWidth + "*" + profile.videoFrameHeight), encoder);
return profile;
} catch (final RuntimeException re) {
Log.e("Profile", re.getLocalizedMessage());
}
}
return null;
}
顺便说一句,QUALITY\u CIF
(352×288)在大多数设备上都有效