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
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
setCamera
)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 :)
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);
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With