Problem with android MediaRecorder setVideoSize()

空扰寡人 提交于 2019-11-30 18:10:52

I had an issue similar to what is described here. I turned out that I had to restructure my code slightly before I could adjust the video size.

The important thing is that setVideoSize() is called before setVideoEncoder(). I can't find this in the documentation, however it solved my problems with setting a specific video resolution. Also keep in mind that setOutputFormat() should be called before setVideoSize().

As as side note the same is true for setVideoFrameRate(). If it is not called before setVideoEncoder() it will not have any affect.

This was tested with Android 2.3.3

Here is a code example:

recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoSize(640,480);
recorder.setVideoFrameRate(30);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);       

First you are going to want to determine what your Camera supports. Try:

            List<String> anti = params.getSupportedAntibanding(); 
    List<String> color = params.getSupportedColorEffects();
    List<String> focus = params.getSupportedFocusModes(); 
    List<String> flash = params.getSupportedFlashModes();
    List<Size> previewSize = params.getSupportedPreviewSizes();
    List<Size> sizes = params.getSupportedPictureSizes();
    List<Integer> frameRates = params.getSupportedPreviewFrameRates();
    List<Integer> pictureFormats = params.getSupportedPictureFormats();
    List<String> scene = params.getSupportedSceneModes(); 
    List<String> white = params.getSupportedWhiteBalance();

This will tell you all of the Camera's supported parameters. Second Make sure that you initialize your MediaRecorder properly see the google documentation for the order in which you need to set the MediaRecorder. Also, if your Camera.setPreviewSize and MediaRecorder.setVideoSize are different it can cause odd behavior.

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