我有这样的代码来剪切我的AVAsset视频:
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:_url options:nil];
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@",_url] error:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *outputURL = paths[0];
NSFileManager *manager = [NSFileManager defaultManager];
[manager createDirectoryAtPath:outputURL withIntermediateDirectories:YES attributes:nil error:nil];
outputURL = [outputURL stringByAppendingPathComponent:@"output.mp4"];
[manager removeItemAtPath:outputURL error:nil];
exportSession.outputURL = [NSURL fileURLWithPath:outputURL];
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
CMTime start = CMTimeMakeWithSeconds(slider.min*(videoDuration-1), 600);
CMTime duration = CMTimeMakeWithSeconds(slider.max*(videoDuration-1), 600);
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void) {
switch (exportSession.status) {
case AVAssetExportSessionStatusCompleted:
_url = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@",outputURL]];
break;
default:
break;
}
}];问题是:将AVAsset保存到URL并重新加载需要一段时间。能让它更快吗?
发布于 2016-08-25 21:30:00
您可以使用AVAssetExportPresetPassthrough作为预先设置的名称,而不是AVAssetExportPresetHighestQuality。这样您可能可以避免昂贵的代码转换。设置一个时间范围可能会排除某些格式的这种情况,但值得一试。
https://stackoverflow.com/questions/39152153
复制相似问题