如何在xamarin中调整相机的视频质量

时间:2018-04-20 04:02:55

标签: c# xamarin.forms

我想从我的应用上传视频到服务器,现在我可以上传小尺寸的视频,但是在尺寸较大的情况下,视频上传没有完成。我怎么能这样做。

我发现2分钟视频的大小为300 MB,因此如何在不丢失质量的情况下缩小视频大小

请有人帮帮我..

以下是我的视频拍摄代码

return_day(4)

UploadVideo

  private async void TakeVideo_Clicked(object sender, EventArgs e)
    {
        if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakeVideoSupported)
        {
            await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
            return;
        }

        var _file = await CrossMedia.Current.TakeVideoAsync(new Plugin.Media.Abstractions.StoreVideoOptions
        {
            Name = "gtsvideo.mp4",
            Directory = "GTSVideos",
        });

        if (_file == null)
        {
            return;
        }
        else
        {
            _path = _file.Path;

            using (var _streamReader = new StreamReader(_file.GetStream()))
            {
                var _array = default(byte[]);                 

                using (MemoryStream _memoryStream = new MemoryStream())
                {
                    _streamReader.BaseStream.CopyTo(_memoryStream);                  

                    _array = _memoryStream.ToArray();                        

                    if (await DisplayAlert(App._confirmation, "It may take few Minutes..,Do you want to save the video?", "Yes", "Cancel"))
                    {
                        FileUploadAsync(_array, false);
                        activity_Indicator.IsVisible = true;
                        activity_Indicator.IsRunning = true;
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
    }



   public async void FileUploadAsync(byte[] fileUpload, bool IsImage)
    {

        APIResponse _response = await App.DataManager.UpdateFilesAsync(_task.ID, fileUpload, IsImage);

        if (IsImage == false)
         {                
           await System.Threading.Tasks.Task.Delay(5000);
         }

        if (_response != null)
        {
            activity_Indicator.IsRunning = false;

            if (IsImage)
            {
                DependencyService.Get<IAlertPlayer>().AlertMessege("Image upload successfully");
            }
            else
            {
                DependencyService.Get<IAlertPlayer>().AlertMessege("Video upload successfully");
            }
        }
        else
        {
            DisplayAlertMessage();
        }
    }      

1 个答案:

答案 0 :(得分:0)

简单的答案:除非您自己实现一些精美的无损压缩代码,否则您不会这样做。您将获得手机操作系统所提供的功能。