Compress Video in Xamarin forms

Vasanthakumar M 251 Reputation points
2021-05-05T05:26:14.133+00:00

Hi Experts,

I want to compress video in Xamarin forms ?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JessieZhang-MSFT 7,706 Reputation points Microsoft Vendor
    2021-05-05T07:24:03.177+00:00

    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.