MediaRecorder setVideoSize shows different behaviour in different devices

后端 未结 2 1347
梦如初夏
梦如初夏 2021-02-06 06:45

I am using media recorder to record video in an android app.

mMediaRecorder.setCamera(mServiceCamera);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.D         


        
2条回答
  •  伪装坚强ぢ
    2021-02-06 07:21

    You need to understand that the preview and the actual captured video are two different things, likewise Preview sizes and Video sizes are two different parameters. What you see in the viewfinder is essentially the preview, but it is not what actually gets recorded.

    1. When starting a camera, you set the preview size to the camera. But you must query for the supported preview sizes and should set one among them.

      Camera camera = camera.open(); List psizes = camera.getParameters() .getSupportedPreviewSizes();

    2. Once you have set up the preview, you can start recording by using a MediaRecorder, and the video size can be set to the media recorder, and it is the actual size of the video that will be captured. Again, you should set one of supported video size.

      List sizes = camera.getParameters() .getSupportedVideoSizes();

    and then, you can set one of these to the media recorder

    mediaRecorder.setVideoSize(videoWidth, videoHeight);
    

    So, remember to check for the supported sizes always, else you are bound to get an app crash.

提交回复
热议问题