MOV转换成MP4


+ (void)videoTranscodingWithPath:(NSString *)path sucess:(SuccessBlock)successBlock failure:(FailureBlock)failureBlock
{
    AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:path] options:nil];
    NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
    NSString *fileName = [path lastPathComponent];
    fileName = [fileName stringByDeletingPathExtension];
    if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])   
    {
        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetPassthrough];
        NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *path = [pathArray objectAtIndex:0];
        NSString *exportPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@.mp4",fileName]];
        exportSession.outputURL = [NSURL fileURLWithPath:exportPath];
        NSLog(@"%@", exportPath);
        exportSession.outputFileType = AVFileTypeMPEG4;
        [exportSession exportAsynchronouslyWithCompletionHandler:^{
            switch ([exportSession status]) {
                case AVAssetExportSessionStatusFailed:
                    NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
                    failureBlock(@"转码失败");
                    break;
                case AVAssetExportSessionStatusCancelled:
                    NSLog(@"Export canceled");
                    failureBlock(@"转码失败");
                    break;
                case AVAssetExportSessionStatusCompleted:
                    NSLog(@"转换成功");
                    successBlock(exportPath);
                    break;
                default:
                    failureBlock(@"转码失败");
                    break;
            }      
        }];
    }
}

你可能感兴趣的:(MOV转换成MP4)