使用MediaRecorder录制时,水平“条”而不是视频
主题A:水平酒吧
这是一个奇怪的。 视频记录和声音很好,但那些酒吧代表我的手。 这就好像我正在寻找一个带肋的pyrex碗:
主题B:
我正在使用前置摄像头(API 16)在Samsung Galaxy Note 10.1上测试此功能。 一些说明:
我使用CamcorderProfile
来选择适当的MediaRecorder
设置。 这是我的代码:
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private boolean prepareVideoRecorder() {
// Get screen width and height for supported video sizes
Display display = getWindowManager().getDefaultDisplay();
int width, height;
if (Build.VERSION.SDK_INT < 13) {
width = display.getWidth();
height = display.getHeight();
} else {
Point size = new Point();
display.getSize(size);
width = size.x;
height = size.y;
}
// Check and set the highest quality available recording profile of the camera.
int frontCamera = Camera.CameraInfo.CAMERA_FACING_FRONT;
CamcorderProfile profile = null;
if (CamcorderProfile.hasProfile(frontCamera, CamcorderProfile.QUALITY_1080P))
profile = CamcorderProfile.get(frontCamera, CamcorderProfile.QUALITY_1080P);
else if (CamcorderProfile.hasProfile(frontCamera, CamcorderProfile.QUALITY_720P))
profile = CamcorderProfile.get(frontCamera, CamcorderProfile.QUALITY_720P);
else if (CamcorderProfile.hasProfile(frontCamera, CamcorderProfile.QUALITY_480P))
profile = CamcorderProfile.get(frontCamera, CamcorderProfile.QUALITY_480P);
else if (CamcorderProfile.hasProfile(frontCamera, CamcorderProfile.QUALITY_HIGH))
profile = CamcorderProfile.get(frontCamera, CamcorderProfile.QUALITY_HIGH);
mCamera = CameraHelper.getDefaultFrontFacingCameraInstance();
// Need to make sure that our recording video size is supported by the camera.
// Query camera to find all sizes and choose the optimal size given the dimensions of screen.
Camera.Parameters parameters = mCamera.getParameters();
List<Camera.Size> mSupportedVideoSizes = parameters.getSupportedVideoSizes();
Camera.Size optimalSize = CameraHelper.getOptimalRecordingSize(mSupportedVideoSizes,
width, height);
// link camera to preview surface
try {
mCamera.setPreviewDisplay(mPreview.getHolder());
} catch (IOException e) {
Log.e(TAG, "Surface text is unavailable or unsuitable for preview" + e.getMessage());
return false;
}
// Unlock the camera to allow the Media Recorder to own it
mCamera.unlock();
// Create and assign the Camera to the Media Recorder
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setCamera(mCamera);
// Set Sources
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
if (profile != null) {
profile.videoFrameWidth = optimalSize.width;
profile.videoFrameHeight = optimalSize.height;
mMediaRecorder.setProfile(profile);
}
// Specify the output file
mMediaRecorder.setOutputFile(CameraHelper.getOutputMediaFile(
CameraHelper.MEDIA_TYPE_VIDEO).toString());
// Prepare configured MediaRecorder
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
}
return true;
}
我尝试绕过CamcorderProfile
并尝试使用每个MediaRecorder.VideoEncoder
编码器。 文件格式是.mp4,我不相信这是问题,因为设备上的标准Camera应用程序输出.mp4。 有任何想法吗?
上一篇: Horizontal "bars" instead of video when recording with MediaRecorder