question

VasanthakumarM-3635 avatar image
0 Votes"
VasanthakumarM-3635 asked newxamarin-5426 commented

Compress Video in Xamarin forms

Hi Experts,

I want to compress video in Xamarin forms ?


dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered newxamarin-5426 commented

Hello,


Welcome to our Microsoft Q&A platform!

You should implement this on each platform.

In android, you can refer sample: https://github.com/leye0/XamarinAndroidFFmpeg

And there is a better library here: https://github.com/natario1/Transcoder .

In IOS, try the following code:

         string downloadPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
         string downloadFilePath = Path.Combine(downloadPath, "compressed_video.mp4");

         var asset = AVAsset.FromUrl( NSUrl.FromFilename( sourceFilePath ) );


         AVAssetExportSession export = new AVAssetExportSession (asset, AVAssetExportSession.PresetLowQuality );

         export.OutputUrl = NSUrl.FromFilename( downloadFilePath );
         export.OutputFileType = AVFileType.Mpeg4;
         export.ShouldOptimizeForNetworkUse = true;

         export.ExportAsynchronously(  ( ) => 
         {

                 if( export.Error != null )
                     System.Diagnostics.Debug.WriteLine( export.Error.LocalizedDescription );
         });

Best Regards,


Jessie Zhang


If the response is helpful, please click "Accept Answer" and upvote it.



Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @VasanthakumarM-3635 ,I have not heard from you for a couple of days. Please let me know if there is anything that I can help here.

0 Votes 0 ·

Hi @JessieZhang-2116 When I recorded a video in 30 seconds, the size was 98 MB when I upload same video while not compress it shows original file size

0 Votes 0 ·

in IOS

0 Votes 0 ·