How to set session AVAssetExportSession in ios?

Posted by  marcel ethan
iPhone  Ios 
 1899  View(s)
Rate this:
NSArray *pres = [AVAssetExportSession exportPresetsCompatibleWithAsset:asset];
        if([pres containsObject:AVAssetExportPreset640x480]) {
            AVAssetExportSession *session = [[AVAssetExportSession alloc]initWithAsset:asset presetName:AVAssetExportPreset640x480];
            FileManagerUtilities *fUtil = [[FileManagerUtilities alloc]init];
            session.outputURL = [NSURL fileURLWithPath:[fUtil searchPathDirectory:NSDocumentDirectory byAppendingDirectoryPath:nil andFileName:@""]];
            session.outputFileType = AVFileTypeQuickTimeMovie;
            session.fileLengthLimit = 10.0;
            [session exportAsynchronouslyWithCompletionHandler:^{
                switch ([session status]) {
                    case AVAssetExportSessionStatusFailed:
                        NSLog(@"Export failed: %@", [[session error] localizedDescription]);
                    case AVAssetExportSessionStatusCancelled:
                        NSLog(@"Export canceled");
I am trying to set session.fileLengthLimit to 10mb but don't know what mistake I am doing. Unable to limit the size to 10mb, how to set fileLengthLimit to 10mb.
  1. Re: How to set session AVAssetExportSession in ios?

    An AVAssetExportSession object transcodes the contents of an AVAsset source object to create an output of the form described by a specified export preset.

    The fileLenghtLimit should be in bytes, ie:

    session.fileLengthLimit = 10*1024*1024;

      Modified On Apr-06-2018 01:03:08 AM