mediarecorder.setVideoSize() fails with maximum resolution

别说谁变了你拦得住时间么 提交于 2019-12-23 23:14:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!