Android mediarecorder only records horrible video
So, I have the following code to write, and the quality is absolutely terrible. I think I must be wrong, but I tried it both ways. The "CamcorderProfile" path and then the "Manual" way, you can see that the camcorder code is commented out. Both give accurate results.
Camera _camera = Camera.Open (1);
_camera.Unlock ();
recorder = new MediaRecorder ();
recorder.SetCamera (_camera);
recorder.SetAudioSource (AudioSource.Mic);
recorder.SetVideoSource (VideoSource.Camera);
recorder.SetOutputFormat (OutputFormat.Default);
recorder.SetAudioEncoder (AudioEncoder.Default);
recorder.SetVideoEncoder (VideoEncoder.Default);
//CamcorderProfile p = CamcorderProfile.Get(0, CamcorderQuality.High);
//recorder.SetProfile(p);
recorder.SetOutputFile (path);
recorder.SetPreviewDisplay(video.Holder.Surface);
recorder.Prepare ();
recorder.Start ();
And it works fine, but here's the problem. This is the image of the preview window while recording, and this is the image of the video as I play it back. You can't tell because the screenshot is so terrible, but none of the colors fit (it has almost no color). I think there must be some problem with the color channels. For example, here's another comparison with a "camera dummy". Below is the correct version . And here's the weird version of the replay.
source to share
This is a working example using the following configuration:
myCamera = getCameraInstance();
mediaRecorder = new MediaRecorder();
myCamera.unlock();
mediaRecorder.setCamera(myCamera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mediaRecorder.setOutputFile(getExternalStorageDirectory() + "myvideo.mp4");
mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
mediaRecorder.setMaxFileSize(5000000); // Set max file size 5M
mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());
However, if you are using Android 5, you must use the new camera API .
source to share