Horizontal "bars" instead of video when recording with MediaRecorder
Subject A: Horizontal Bars
This is a weird one. The video records and the sound is fine, but those bars represent my hand. It is as if I am looking a ribbed pyrex bowl:
Subject B:
I am testing this on a Samsung Galaxy Note 10.1 using the front facing camera (API 16). Some notes:
I use CamcorderProfile
to select the appropriate MediaRecorder
settings. Here is my code:
@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;
}
I've tried bypassing the CamcorderProfile
and trying every MediaRecorder.VideoEncoder
encoder available. The file format is .mp4, which I don't believe is the issue because the standard Camera app on the device outputs a .mp4. Any ideas?