美文网首页
MOV转换成MP4

MOV转换成MP4

作者: XChn | 来源:发表于2017-06-27 15:13 被阅读0次
    
    + (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

          本文链接:https://www.haomeiwen.com/subject/utjecxtx.html