我正在使用 AVAssetExportSession 和 AVURLAsset 也导入了与之相关的库。
我的代码是
NSData *data = [NSData dataWithContentsOfURL:movieUrl];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"capturedvideo1.MOV"];
NSURL *url = [NSURL URLWithString:path];
[data writeToFile:path atomically:YES];
//Delete the original asset
NSArray *paths1 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory1 = [paths1 objectAtIndex:0];
NSString *path1 = [NSString stringWithFormat:@"%@/%@", documentsDirectory1,@"capturedvideo11.MOV"];
NSURL *url1 = [NSURL URLWithString:path1];
[self convertVideoToLowQuailtyWithInputURL:url outputURL:url1 handler:Nil];
- (void)convertVideoToLowQuailtyWithInputURL:(NSURL*)inputURL
outputURL:(NSURL*)outputURL
handler:(void (^)(AVAssetExportSession*))handler
{
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetMediumQuality];
exportSession.outputURL = outputURL;
if ([[UIApplication sharedApplication]canOpenURL:inputURL]){
NSLog(@"open");
}
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
NSLog(@"%@", exportSession.error);
[exportSession exportAsynchronouslyWithCompletionHandler:^(void)
{
if(exportSession.status != AVAssetExportSessionStatusCompleted){
NSLog(@"%@", exportSession.error);
}
}];
}
但我得到以下错误
Error Domain=NSURLErrorDomain Code=-1 "unknown error" UserInfo=0x1da3aed0
NSErrorFailingURLStringKey=/var/mobile/Applications/6EF91ECE-9E7A-4019-9F07-6DFE028EFFEA/Documents
/capturedvideo1.MOV, NSErrorFailingURLKey=/var/mobile/Applications/6EF91ECE-
9E7A-4019-9F07-6DFE028EFFEA/Documents/capturedvideo1.MOV, NSLocalizedDescription=unknown error,
NSUnderlyingError=0x1da3ef70 "The operation couldn’t be completed. (OSStatus error -12935.)",
NSURL=/var/mobile/Applications/6EF91ECE-9E7A-4019-9F07-6DFE028EFFEA/Documents/capturedvideo1.MOV}
我想减小视频文件的大小。视频质量很高。