Skip to content

Instantly share code, notes, and snippets.

@ShravanJ

ShravanJ/gist.cs Secret

Last active Feb 6, 2019
Embed
What would you like to do?
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