剪视频

作者: 吾家有谷粒儿 | 来源:发表于2018-01-17 15:35 被阅读0次

    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;

                }

            }];

        }

    相关文章

      网友评论

          本文标题:剪视频

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