Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set video quality for media recorder.video produces flickering video

mMediaRecorder = new MediaRecorder();
    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();
    mMediaRecorder.setCamera(mCamera);
    // Step 2: Set sources
    // activate this for recording with sound\

    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

    mMediaRecorder.setVideoSize(getMaxSupportedVideoSize().width,getMaxSupportedVideoSize().height);

    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    // Step 4: Set output file
    mMediaRecorder.setOutputFile(getOutputMediaFile("movie"));

    // Step 4: Set output file
    mMediaRecorder.setOutputFile(getOutputMediaFile("movie"));


    // Step 5: Set the preview output
    mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

    mMediaRecorder.setOrientationHint(90);

above code is working fine But, the quality of video is not as same as video i shoot over native android camera, my video recorded using media recorder is poor quality compare to the native one, how can i improve the video quality.

If any one knows help me out.Thanks

like image 693
Jignesh Jain Avatar asked Jun 05 '14 08:06

Jignesh Jain


3 Answers

I'm not a Java/Android dev, I'm using Xamarin and C#, but I had much the same problem, and my solution should be directly applicable (even the syntax is almost identical).

I found that if you're using setCamera (and are previewing what the camera sees before you start up your mediaRecorder) then it won't let you change the quality settings on the mediaRecorder.

And then when you call mediaRecorder.start(), it either crashes or freezes or displays garbage.

Basically, as long as the Camera is previewing, the MediaRecorder won't be allowed to start recording at a different quality to that which the camera already has. You need to

  1. stop the camera preview,
  2. take away its preview surface
  3. assign the camera to the MediaRecorder (with setCamera)
  4. set the MediaRecorder up with the quality you need
  5. then reattach the preview surface

Then when you start recording, everything works as it should.

So in your case, just before you call mediaRecorder.setCamera(), try the following:

mCamera.stopPreview(); mCamera.setPreviewDisplay(null);

Then further down, do your

mRecorder.setCamera()

That was the solution for me. I can now set the video quality to 720p (or 1080p) and it works perfectly.

However, when you stop recording, your previewing will also stop.

You'll probably need to reinstate your

mCamera.setPreviewDisplay(mPreview.getHolder().getSurface())

to what it was before, and restart the actual preview.

I hope it works for you too :)

like image 92
wislon Avatar answered Nov 19 '22 07:11

wislon


Alternative 1

recorder.setVideoSize(640, 480);
recorder.setVideoFrameRate(16); //might be auto-determined due to lighting
recorder.setVideoEncodingBitRate(3000000);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);// MPEG_4_SP
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

Alternative 2

CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);
like image 36
Raju yourPepe Avatar answered Nov 19 '22 08:11

Raju yourPepe


Replace this code:

    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);

mMediaRecorder.setVideoSize(getMaxSupportedVideoSize().width,getMaxSupportedVideoSize().height);

mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

with :

    mMediaRecorder.setProfile(CamcorderProfile
            .get(CamcorderProfile.QUALITY_HIGH));
like image 1
abhishek kumar gupta Avatar answered Nov 19 '22 07:11

abhishek kumar gupta