IOS视频压缩功能实现

来源:互联网 发布:www.47es.com最新域名 编辑:程序博客网 时间:2024/06/05 04:01
         NSString *path=@ “视频原路径”         NSString *bakPath=@ “视频新路径”//新路径不能存在文件 如果存在是不能压缩成功的        AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:path] options:nil];        AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPreset1280x720];        exportSession.outputURL = [NSURL fileURLWithPath:bakPath];        exportSession.outputFileType = AVFileTypeMPEG4;        exportSession.shouldOptimizeForNetworkUse= YES;        [exportSession exportAsynchronouslyWithCompletionHandler:^(void)         {             BOOL goToUploadFile=NO;             switch (exportSession.status) {                 case AVAssetExportSessionStatusCancelled:                     NSLog(@"AVAssetExportSessionStatusCancelled");                     break;                 case AVAssetExportSessionStatusUnknown:                     NSLog(@"AVAssetExportSessionStatusUnknown");                     break;                 case AVAssetExportSessionStatusWaiting:                     NSLog(@"AVAssetExportSessionStatusWaiting");                     break;                 case AVAssetExportSessionStatusExporting:                     NSLog(@"AVAssetExportSessionStatusExporting");                     break;                 case AVAssetExportSessionStatusCompleted:                                       _path=bakPath;                  //压缩成功                                    break;                 case AVAssetExportSessionStatusFailed:                 {                     NSError *error=exportSession.error;                     if (error) {                                           }                 }                                         break;                  default:                                         break;             }                     }];

原创粉丝点击