iOS开发-进阶:MOV格式视频转MP4格式

AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:sourceUrl options:nil];

    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];

    NSLog(@"%@",compatiblePresets);

    if ([compatiblePresets containsObject:AVAssetExportPresetHighestQuality]) {

        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPresetMediumQuality];

        NSDateFormatter *formater = [[NSDateFormatter alloc] init];//用时间给文件全名,以免重复

        [formater setDateFormat:@"yyyy-MM-dd-HH:mm:ss"];

        NSString * resultPath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/output-%@.mp4", [formater stringFromDate:[NSDate date]]];

        NSLog(@"resultPath = %@",resultPath);

        exportSession.outputURL = [NSURL fileURLWithPath:resultPath];

        exportSession.outputFileType = AVFileTypeMPEG4;

        exportSession.shouldOptimizeForNetworkUse = YES;

        [exportSession exportAsynchronouslyWithCompletionHandler:^(void)

         {

             switch (exportSession.status) {

                 case AVAssetExportSessionStatusUnknown:

                     NSLog(@"AVAssetExportSessionStatusUnknown");

                     break;

                 case AVAssetExportSessionStatusWaiting:

                     NSLog(@"AVAssetExportSessionStatusWaiting");

                     break;

                 case AVAssetExportSessionStatusExporting:

                     NSLog(@"AVAssetExportSessionStatusExporting");

                     break;

                 case AVAssetExportSessionStatusCompleted:

                     NSLog(@"AVAssetExportSessionStatusCompleted");

                     break;

                 case AVAssetExportSessionStatusFailed:

                     NSLog(@"AVAssetExportSessionStatusFailed");

                     break;

             }

         }];

    }


你可能感兴趣的:(iOS)