最后我找到了解决方案。
我们可以使用AVAssetExportSession
来修剪视频而不显示UIVideoEditorController
。
我的代码是这样的:
- (void)splitVideo:(NSString *)outputURL
{
@try
{
NSString *videoBundleURL = [[NSBundle mainBundle] pathForResource:@"Video_Album" ofType:@"mp4"];
AVAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:videoBundleURL] options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:asset];
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
[self trimVideo:outputURL assetObject:asset];
}
videoBundleURL = nil;
[asset release];
asset = nil;
compatiblePresets = nil;
}
@catch (NSException * e)
{
NSLog(@"Exception Name:%@ Reason:%@",[e name],[e reason]);
}
}
这种方法修剪视频
- (void)trimVideo:(NSString *)outputURL assetObject:(AVAsset *)asset
{
@try
{
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
exportSession.outputURL = [NSURL fileURLWithPath:outputURL];
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
CMTime start = CMTimeMakeWithSeconds(splitedDetails.startTime, 1);
CMTime duration = CMTimeMakeWithSeconds((splitedDetails.stopTime - splitedDetails.startTime), 1);
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
[self checkExportSessionStatus:exportSession];
[exportSession release];
exportSession = nil;
}
@catch (NSException * e)
{
NSLog(@"Exception Name:%@ Reason:%@",[e name],[e reason]);
}
}
此方法检查修整的状态:
- (void)checkExportSessionStatus:(AVAssetExportSession *)exportSession
{
[exportSession exportAsynchronouslyWithCompletionHandler:^(void)
{
switch ([exportSession status])
{
case AVAssetExportSessionStatusCompleted:
NSLog(@"Export Completed");
break;
case AVAssetExportSessionStatusFailed:
NSLog(@"Error in exporting");
break;
default:
break;
}
}];
}
我打电话splitVideo
方法从导出按钮操作方法并通过输出UR L作为参数。
u能为我提供乌尔修剪视频,在这里用户可以选择开始和结束时间码? –