0

I am using Xam.Plugin.Media to capture a photo and record a video. The problem is the file size of the video always above 20MB.

I tried to put the settings to the lowest still getting a 20MB file size for a 20 seconds video. I am using Samsung Galaxy A9 (2018). Can I use FFMPEG to reduce the file size?

private async void btnCamera4_Clicked(object sender, EventArgs e)   
{
   var cafNo = entCafNo.Text;
   TimeSpan time = new TimeSpan(0, 0, 0, 20, 0);

   await CrossMedia.Current.Initialize();

   if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakeVideoSupported)
   {
      await DisplayAlert("No Camera", "No Camera Available", "Ok");
      return;
   }

   try
   {
       var file = await CrossMedia.Current.TakeVideoAsync(
       new Plugin.Media.Abstractions.StoreVideoOptions
       {
           Name = cafNo + "_VID.mp4",
           CompressionQuality = 0,
           Quality = VideoQuality.Low,
           DesiredLength = time
        });

        entVideoUrl.Text = file.Path;
    }
    catch (Exception ex)
    {
        Crashes.TrackError(ex);
    }
}

1 Answers1

0

If you see this awesome blog by Xamarian's

There is native code with how to use it for proper video compression natively. Since it is the native code you can also edit it as per your requirement.

In case of queries feel free to revert

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
  • I browsed on the comments and they said that ffmpeg is not working for api 6 and above I need to lower the file size because I am getting a out of memory exception –  Dec 28 '18 at 15:05
  • Ffmpeg was never an option did you check the guide in that answer? – FreakyAli Dec 29 '18 at 12:08
  • I have fixed it I added LargeHeap Settings my problem now is the Java.Net.SocketException: Socket closed when sending the data to server –  Dec 30 '18 at 06:02
  • Setting LargeHeap is a bad practice but okay so the socketExpection stack trace would help here – FreakyAli Dec 31 '18 at 07:33
  • what can I do to prevent using largeheap? –  Dec 31 '18 at 10:36
  • well there are a lot of things check this answer which explains it https://stackoverflow.com/a/30930239/7462031 – FreakyAli Dec 31 '18 at 10:38
  • What are the reason(s) why the socket is closing? –  Jan 02 '19 at 06:30
  • there could be n number of reasons I will need the stack trace to point it out to you – FreakyAli Jan 02 '19 at 06:44