Android video quality?

I use the media recorder class to record video, I initialize the recorder with the following properties,

recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); 

But the video quality is not the same as the video that I shoot on my own Android camera, my video recorded using a media recorder is of poor quality compared to the original one, how to improve the quality of the video.

If anyone knows that I'm helping me. thanks

+6
source share
4 answers

Finally, I found code for recording high-quality video in android 2.1 by setting videoEncodingBitRate, AudioEncodingBitRate, AudioSamplingRate ... etc. Using this method, you can set properties for the video no matter what you want to provide high-quality video.

For setting high quality and low quality, refer to this page,

http://www.andgps.com/20110410/camcorderprofile-predefined-camcorder-profile-settings-for-camcorder-applications

The i code used with the base version of Android 2.1 to create high-quality video is shown below.

  recorder = new MediaRecorder(); Method[] methods = recorder.getClass().getMethods(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setVideoFrameRate(24); recorder.setVideoSize(720, 480); for (Method method: methods){ try{ if (method.getName().equals("setAudioChannels")){ method.invoke(recorder, String.format("audio-param-number-of-channels=%d", 1)); } else if(method.getName().equals("setAudioEncodingBitRate")){ method.invoke(recorder,12200); } else if(method.getName().equals("setVideoEncodingBitRate")){ method.invoke(recorder, 3000000); } else if(method.getName().equals("setAudioSamplingRate")){ method.invoke(recorder,8000); } else if(method.getName().equals("setVideoFrameRate")){ method.invoke(recorder,24); } }catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); 

`

+11
source

use the following settings for movies: -

 private void cameraSettings() { mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); mediaRecorder.setVideoSize(width, height); mediaRecorder.setVideoFrameRate(videoFramePerSecond); } 

use videoFramePerSecond = 30 and width = 1280 and height = 720 .. You can make this parameter yourself as you wish.

+4
source

try it

mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH)); mrec.setPreviewDisplay(surfaceHolder.getSurface());

+2
source

Try adding this line.

  recorder.setVideoSize(640,480); 

Or check the screen resolutions supported by your device and set the best option.

0
source

Source: https://habr.com/ru/post/891008/


All Articles