Skip to content Skip to sidebar Skip to footer

Video Quality In Android?

I am using the media recorder class for recording video, I initialize the recorder with following properties, recorder = new MediaRecorder(); recorder.setAudioSource(MediaR

Solution 1:

Finally I found the code to record high quality video in android 2.1 by setting videEncodingBitRate , AudioEncodingBitRate, AudioSamplingRate ...etc. Using this method you can set the properties for video whatever you want to provide high quality video.

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

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

The code i used with base version android 2.1 to produce 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));
        } 
        elseif(method.getName().equals("setAudioEncodingBitRate")){
                method.invoke(recorder,12200);
            }
        elseif(method.getName().equals("setVideoEncodingBitRate")){
            method.invoke(recorder, 3000000);
        }
        elseif(method.getName().equals("setAudioSamplingRate")){
            method.invoke(recorder,8000);
        }
        elseif(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);

`

Solution 2:

use the following settings for Video Recordings:-

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.. This setting you can do by your own as per your requirment.

Solution 3:

try this

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

Solution 4:

Try adding this line

 recorder.setVideoSize(640,480); 

Or check out the screen resolutions supported by your device and set the best one accordingly.

Solution 5:

To enhance the video quality, you should consider setting the video size on your mediaRecorder instance to the max resolution of your device.

This snippet will do the job

WindowManager wm = (WindowManager) getBaseContext().getSystemService(Context.WINDOW_SERVICE);
Point size = new Point();
wm.getDefaultDisplay().getRealSize(size);

mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setOutputFile(file.toString());
mMediaRecorder.setVideoEncodingBitRate(10000000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.HEVC);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mMediaRecorder.setVideoSize(size.y, size.x);
int rotation =getWindowManager().getDefaultDisplay().getRotation();
switch (mSensorOrientation) {
    case SENSOR_ORIENTATION_DEFAULT_DEGREES:
        mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation));
        break;
    case SENSOR_ORIENTATION_INVERSE_DEGREES:
        mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation));
        break;
}
mMediaRecorder.prepare();

Post a Comment for "Video Quality In Android?"