我正在使用Camera2录制视频。要获得可用分辨率列表,我们有两个选项:
// CAMCORDER_PROFILES is an int array listing all the profiles ids
for(int profileId : CAMCORDER_PROFILES) {
if(CamcorderProfile.hasProfile(profileId)) {
CamcorderProfile profile = CamcorderProfile.get(profileId);
// Here we can get a resolution with profile.videoFrameWidth & profile.videoFrameHeight
}
}
和
private void startRecordingVideo() {
if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewResolution) {
return;
}
try {
closeCaptureSession();
setUpMediaRecorder();
SurfaceTexture texture = mTextureView.getSurfaceTexture();
assert texture != null;
texture.setDefaultBufferSize( (int) mPreviewResolution.getWidth(), (int) mPreviewResolution.getHeight());
List<Surface> surfaces = new ArrayList<>();
// Set up Surface for the camera preview
Surface previewSurface = new Surface(texture);
surfaces.add(previewSurface);
mPreviewRequestBuilder.addTarget(previewSurface);
// Set up Surface for the MediaRecorder
Surface recorderSurface = mMediaRecorder.getSurface();
surfaces.add(recorderSurface);
mPreviewRequestBuilder.addTarget(recorderSurface);
// Start a capture session:
mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
mCaptureSession = cameraCaptureSession;
updatePreview();
// Start recording
mMediaRecorder.start();
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
Log.e(this, "Unable to start recording video");
}
}, mBackgroundHandler);
}
catch (CameraAccessException | IOException e) {
e.printStackTrace();
}
}
起初我只使用选项2。在我尝试使用三星Galaxy A3 2016之前一切正常。在这台设备上,如果我尝试使用1920 * 1080分辨率,则会因此错误而失败:
E / CameraDevice-0-LE:表面尺寸(w = 1920,h = 1080),格式为0x1 无效,大小不在有效集中:[960x720,880x720,720x720, 720x480,640x480,352x288,320x240,176x144]
为了解决这个问题,我现在得到一个配置文件,其分辨率在map.getOutputSizes(MediaRecorder.class)的结果中。我工作,但我能用的最好的配置文件是640x480,这还不足以满足我的需求。
有没有办法在A3上使用1920 * 1080分辨率和Camera2?或者该解决方案仅适用于Samsung SDK ???
编辑:这是我开始录制视频时的所作所为:
{{1}}
答案 0 :(得分:2)
A3有一台Legacy相机。这意味着camera2 API是旧Camera API的包装器。很多时候,这个包装器引入的麻烦比它解决的更麻烦。我建议直接通过旧的Camera API使用此设备和其他旧设备。