-
-
Save ShravanJ/47eae4f1d4ab36c74f014ccd6c9dbf04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<Stream> CompressVideo(MediaFile file) | |
{ | |
string exportPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); | |
string exportFilePath = Path.Combine(exportPath, "compressed_video.mp4"); | |
System.Diagnostics.Debug.WriteLine("Export path: " + exportPath); | |
System.Diagnostics.Debug.WriteLine("Export file path: " + exportFilePath); | |
var asset = AVAsset.FromUrl(NSUrl.FromFilename(file.Path)); | |
AVAssetExportSession export = new AVAssetExportSession(asset, AVAssetExportSessionPreset.MediumQuality); | |
System.Diagnostics.Debug.WriteLine("Created export object"); | |
export.OutputUrl = NSUrl.FromFilename(exportFilePath); | |
export.OutputFileType = AVFileType.Mpeg4; | |
export.ShouldOptimizeForNetworkUse = true; | |
System.Diagnostics.Debug.WriteLine("Preparing to export"); | |
await runExportAsync(export); | |
Stream exportStream = File.OpenRead(exportFilePath); | |
System.Diagnostics.Debug.WriteLine("Stream read from file"); | |
return exportStream; | |
} | |
private async Task RunExportAsync(AVAssetExportSession exp) | |
{ | |
await exp.ExportTaskAsync(); | |
if (exp.Status == AVAssetExportSessionStatus.Completed) | |
{ | |
System.Diagnostics.Debug.WriteLine("Finished export"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment