Created
April 8, 2019 22:56
-
-
Save kmdarshan/b56c06d8a432a3639911f9adc609aed4 to your computer and use it in GitHub Desktop.
Exporting media in iOS
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
// First thing is you need a AVAsset. | |
// Once you have an asset, you need to determine the type of preset you need to use. | |
// You can consider a preset as a set of properties, which is provided to the exporter. | |
// I do this for helping me with my export. | |
-(NSString*)determineCompatibleExportPresetForAsset:(AVAsset*)asset | |
{ | |
NSArray<NSString*>* presetsRankedByPriority = @[AVAssetExportPresetHighestQuality, AVAssetExportPresetMediumQuality, AVAssetExportPresetLowQuality]; | |
NSArray* compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:asset]; | |
for (NSString* preset in presetsRankedByPriority) | |
{ | |
if([compatiblePresets containsObject:preset]) | |
{ | |
return preset; | |
} | |
} | |
return nil; | |
} | |
// after getting the preset, use this call | |
AVAssetExportSession* exportSession = [AVAssetExportSession exportSessionWithAsset:asset presetName:preset]; | |
exportSession.outputFileType = UTI; | |
exportSession.outputURL = whereToSaveTheFile; | |
if (!exportSession) | |
{ | |
callback([NSError errorWithDomain:kManagerErrorDomain | |
code:kDownloadFailed | |
userInfo:nil]); | |
} | |
else | |
{ | |
[exportSession exportAsynchronouslyWithCompletionHandler: ^{ | |
// handle error here | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment