问题
I tried to find the camera resolution by
final Parameters p = this.camera.getParameters();
List<Size> previewSizes=p.getSupportedPreviewSizes();
and set the video size of media recorder by
this.mediaRecorder.setVideoSize(previewSizes.get(0).width, previewSizes.get(0).height);
I used to record video in Landscape mode.
MediaRecorder
fails to record video with this high resolution.
When I try with less resolution, it is recording.
Is there a problem with screen display size and video size we are setting ?
回答1:
try something like this
getBestPreviewSize () will determine best possible resolution based on provided width and height. The is obviously missing the main mediarecorder and camera setup details but you can find them quite easily and you've probably already done that
...
Camera.size size = getBestPreviewSize(720,480, mCamera.getParameters());
mMediaRecorder.setVideoSize(size.width,size.height);
mMediaRecorder.setVideoFrameRate(15);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
...
private Camera.Size getBestPreviewSize(int width, int height, Camera.Parameters parameters) {
Camera.Size result=null;
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
if (size.width<=width && size.height<=height) {
if (result==null) {
result=size;
} else {
int resultArea=result.width*result.height;
int newArea=size.width*size.height;
if (newArea>resultArea) {
result=size;
}
}
}
}
return(result);
}
来源:https://stackoverflow.com/questions/16785086/mediarecorder-setvideosize-fails-with-maximum-resolution