AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:[[fieldData objectAtIndex:0]objectForKey:@"videopath"] options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
NSDateFormatter *formatter =[[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyyMMddHHmmss"];
videoNameStr =[NSString stringWithFormat:@"%@",[formatter stringFromDate: [NSDate date]]];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
exportPath = [NSString stringWithFormat:@"%@/%@.mp4",
[NSHomeDirectory() stringByAppendingString:@"/tmp"],
videoNameStr];
exportSession.outputURL = [NSURL fileURLWithPath:exportPath];
exportSession.outputFileType = AVFileTypeMPEG4;
url = [NSURL fileURLWithPath:exportPath];
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:
NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
case AVAssetExportSessionStatusCompleted:
NSLog(@"转换成功");
break;
default:
break;
}
}];
}
其中url 为转换后的存贮地址