Xamarin.Android录制视频 - 质量差

时间:2016-07-23 20:09:07

标签: xamarin xamarin.android

我正在使用以下Xamarin教程https://developer.xamarin.com/recipes/android/media/video/record_video/

我可以成功录制视频和音频,但质量不是很好。有人可以建议/解释我如何提高质量吗?

我知道该设备可以录制更高的质量,因为原生相机应用程序记录的质量要高得多。

编辑到目前为止是我的代码

protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.RecordVideo);
            var record = FindViewById<Button>(Resource.Id.Record);
            var stop = FindViewById<Button>(Resource.Id.Stop);
            var play = FindViewById<Button>(Resource.Id.Play);
            var video = FindViewById<VideoView>(Resource.Id.SampleVideoView);
            var videoPlayback = FindViewById<VideoView>(Resource.Id.PlaybackVideoView);
            string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/test.mp4";


            if (Camera.NumberOfCameras < 2)
            {
                Toast.MakeText(this, "Front camera missing", ToastLength.Long).Show();
                return;
            }
            video.Visibility = ViewStates.Visible;
            videoPlayback.Visibility = ViewStates.Gone;

            _camera = Camera.Open(1);
            _camera.SetDisplayOrientation(90);
            _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);
            //var cameraProfile = CamcorderProfile.Get(CamcorderQuality.HighSpeed1080p);
           // recorder.SetProfile(cameraProfile);
            recorder.SetOutputFile(path);

            recorder.SetOrientationHint(270);

            recorder.SetPreviewDisplay(video.Holder.Surface);

            record.Click += delegate
            {

                recorder.Prepare();
                recorder.Start();
            };


            stop.Click += delegate
            {
                if (recorder != null)
                {      
                    video.Visibility = ViewStates.Gone;
                    videoPlayback.Visibility = ViewStates.Visible;
                    recorder.Stop();
                    recorder.Release();                    
                }
            };

            play.Click += delegate
            {
                video.Visibility = ViewStates.Gone;
                videoPlayback.Visibility = ViewStates.Visible;
                var uri = Android.Net.Uri.Parse(path);
                videoPlayback.SetVideoURI(uri);
                videoPlayback.Start();
            };

        }

1 个答案:

答案 0 :(得分:0)

我没有看到在任何地方指定CamcorderProfile的示例,因此您可能希望从中开始。默认帧率,比特率和视频帧大小可能低于您的预期。我现在不是一台计算机,但尝试使用MediaRecorder中的SetProfile方法将配置文件设置为QUALITY_1080p

您需要在设置视频和音频源之后但在调用SetOutputFile方法之前设置配置文件。