I am trying to transfer video between devices. I want to support as old devices as possible. So I started with a class MediaRecorderin Gingerbread (API 10), but it had problems. So now I turn to Bean Jelly (API 16) and MediaCodec.
I upload data to the codec in Camera PreviewCallback. I have to use the same permission for preview, and for the codec. But on some of our test devices, there is no intersection between preview permissions and codecs and their permissions.
So how to capture video on these devices? I know what is createInputSurfacein MediaCodec, but it needs API 18, and I will have to disable more than 35% of the devices, which is unacceptable.
So how to solve it?
Code for finding the best resolution:
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;
}
Encoderdebugger
Btw, QUALITY_CIF(352 Γ 288) is what works on most devices.
source
share