剪视频

NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:self.asset];

    if ([compatiblePresets containsObject:AVAssetExportPresetMediumQuality]) {

        self.exportSession = [[AVAssetExportSession alloc] initWithAsset:self.asset presetName:AVAssetExportPresetPassthrough];

        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

        formatter.dateFormat = @"yyyyMMddHHmmss";

        NSString *str = [formatter stringFromDate:[NSDate date]];

        NSString *videoPath =  [NSTemporaryDirectory() stringByAppendingFormat:@"%@.mp4",str];

        NSURL *furl = [NSURL fileURLWithPath:videoPath];

        self.exportSession.outputURL = furl;

        self.exportSession.outputFileType = AVFileTypeQuickTimeMovie;

        CMTime start = CMTimeMakeWithSeconds(self.startTime, self.asset.duration.timescale);

        CMTime duration = CMTimeMakeWithSeconds(self.stopTime - self.startTime, self.asset.duration.timescale);

        CMTimeRange range = CMTimeRangeMake(start, duration);

        self.exportSession.timeRange = range;

        [self.exportSession exportAsynchronouslyWithCompletionHandler:^{

            switch ([self.exportSession status]) {

                case AVAssetExportSessionStatusFailed:

                    NSLog(@"Export failed: %@", [[self.exportSession error] localizedDescription]);

                    break;

                case AVAssetExportSessionStatusCancelled:

                    NSLog(@"Export canceled");

                    break;

                default:

                    NSLog(@"NONE");

                    dispatch_async(dispatch_get_main_queue(), ^{

                         NSLog(@"剪辑成功");

                    });

                    break;

            }

        }];

    }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容