如何裁剪从画廊获取的视频?

时间:2015-03-10 07:03:18

标签: ios

您好我可以静态裁剪视频,但我想动态剪裁我们从gallery中选择的视频。我可以做如何选择想要裁剪的画廊中的视频,但我没有从画廊到mySAVideoRangeSlider的视频.i让这个链接https://github.com/andrei200287/SAVideoRangeSlider 我的代码是这样的

- (IBAction)videoClicked:(id)sender
{

imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes =
[[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
[self presentViewController:imagePicker animated:YES completion:nil];

}
- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info
{

NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.movie"]){
videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(@"videourl %@",videoURL);

}
[picker dismissModalViewControllerAnimated:YES];
}

- (IBAction)showCroppedVideo:(id)sender
{

[self deleteTmpFile];
//    NSURL *videoFileUrl = [NSURL fileURLWithPath:self.originalVideoPath];
AVAsset *anAsset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:anAsset];
if ([compatiblePresets containsObject:AVAssetExportPresetMediumQuality]) {
self.exportSession = [[AVAssetExportSession alloc]
initWithAsset:anAsset presetName:AVAssetExportPresetPassthrough];

// Implementation continues.
NSURL *furl = [NSURL fileURLWithPath:self.tmpVideoPath];
self.exportSession.outputURL = furl;
self.exportSession.outputFileType = AVFileTypeQuickTimeMovie;
CMTime start = CMTimeMakeWithSeconds(self.startTime, anAsset.duration.timescale);
CMTime duration = CMTimeMakeWithSeconds(self.stopTime-self.startTime, anAsset.duration.timescale);
CMTimeRange range = CMTimeRangeMake(start, duration);
self.exportSession.timeRange = range;
self.CroppedVedioBtn.hidden = YES;
self.activityIndicatorView.hidden = NO;
[self.activityIndicatorView startAnimating];
[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(), ^{
[self.activityIndicatorView stopAnimating];
self.activityIndicatorView.hidden = YES;
self.CroppedVedioBtn.hidden = NO;
[self playMovie:self.tmpVideoPath];
});

break;
}
}];

}
}

我没有动态地从画廊到mySAVideoRangeSlider的视频。请任何人帮我做这个。非常感谢帮助

0 个答案:

没有答案