Ios [exportSession exportAsynchronouslyWithCompletionHandler:^(void){}给出导出错误?
我已经制作了一个示例应用程序,通过从摄影机卷中获取视频来修剪视频。编写的代码如下:Ios [exportSession exportAsynchronouslyWithCompletionHandler:^(void){}给出导出错误?,ios,avassetexportsession,Ios,Avassetexportsession,我已经制作了一个示例应用程序,通过从摄影机卷中获取视频来修剪视频。编写的代码如下: -(IBAction)cutVideo { NSString *path=[NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) objectAtIndex:0]; path=[path stringByAppendingPathComponent:@"new.mov"]; [self spl
-(IBAction)cutVideo
{
NSString *path=[NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) objectAtIndex:0];
path=[path stringByAppendingPathComponent:@"new.mov"];
[self splitVideo:path];
}
- (void)splitVideo:(NSString *)outputURL
{
@try
{
NSURL *fileURL=[[NSURL alloc] init];
fileURL=[NSURL fileURLWithPath:outputURL];
fileURL=[NSURL URLWithString:outputURL];
// NSString *videoBundleURL = [[NSBundle mainBundle] pathForResource:@"samp" ofType:@"mov"];
AVAsset *asset = [[AVURLAsset alloc] initWithURL:fileURL options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:asset];
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality])
{
[self trimVideo:outputURL assetObject:asset];
}
// videoBundleURL = nil;
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(startTime, 1);
CMTime duration = CMTimeMakeWithSeconds((endTime - startTime), 1);
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
if ([[NSFileManager defaultManager] fileExistsAtPath:outputURL])
{
[[NSFileManager defaultManager] removeItemAtPath:outputURL error:nil];
}
[exportSession exportAsynchronouslyWithCompletionHandler: ^(void) {
NSLog(@"Export Status %d %@", exportSession.status, [exportSession.error description]);
}];
exportSession = nil;
}
@catch (NSException * e)
{
NSLog(@"Exception Name:%@ Reason:%@",[e name],[e reason]);
}
}
一切正常,但错误在导出文件中..错误如下
2012-12-12 13:27:27.896 RecordVideo[1472:907] Export Status 4 Error
Domain=NSURLErrorDomain Code=-1 "unknown error" UserInfo=0x1e577ad0
{NSErrorFailingURLStringKey=/var/mobile/Applications/A38CC8B9-A8CB-4A65-8308-
24A9BEB27626/Library/Documentation/new.mov,
NSErrorFailingURLKey=/var/mobile/Applications/A38CC8B9-A8CB-4A65-8308-
24A9BEB27626/Library/Documentation/new.mov, NSLocalizedDescription=unknown error,
NSUnderlyingError=0x1e537da0 "The operation couldn’t be completed. (OSStatus error
-12935.)", NSURL=/var/mobile/Applications/A38CC8B9-A8CB-4A65-8308-
24A9BEB27626/Library/Documentation/new.mov}
感谢您提供的任何帮助,请检查资产是否为零。检查结束时间是否大于开始时间。请通过打印检查结束时间是否大于开始时间。通过手动提供开始和结束时间进行检查。请提供更高的结束时间(不要超过视频的总时间)。您是否能够修复此错误?请说明如何解决。