简体   繁体   English

Android mediarecorder只录制可怕质量的视频

[英]Android mediarecorder only recording terrible quality video

So I have the following code to do my recording and the quality is absolutely terrible. 所以我有以下代码来进行录制,质量非常糟糕。 I think I must have a setting wrong but I have tried it both ways. 我想我必须设置错误,但我已经尝试过两种方式。 The "CamcorderProfile" way and then "Manual" way, you can see the camcorder code is commented out. 以“CamcorderProfile”方式然后以“手动”方式,可以看到摄像机代码被注释掉了。 Both give the exact same 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 this works just fine, but here is the issue. 这很好用,但问题就在这里。 This is a picture of the preview window when I am recording, and this is picture of the video when I play it back. 是我录制时预览窗口的图片, 是播放视频时的视频图片。 You cant actually tell because the screenshot is so terrible, but none of the colors are right either (it has almost no color) I think there must be some sort of issue with the color channels. 你实际上不能说,因为截图是如此可怕,但没有一种颜色是正确的(它几乎没有颜色)我认为颜色通道必定存在某种问题。 For example here is another comparison with the genymotion "dummy camera" . 例如,这是与genymotion“虚拟相机”的另一个比较。 Here is the correct version. 这是正确的版本。 And here is the weird playback version. 这是一个奇怪的播放版本。

This property helps in improving video quality: 此属性有助于提高视频质量:

mediaRecorder.setVideoEncodingBitRate(3000000);  //you may try varying the argument value

and ofcourse call this method before prepare() :) 并且在准备(:)之前调用此方法

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 use Android 5 you should use the new camera API . 但是,如果您使用Android 5,则应使用新的相机API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM