Objective c 剪得更快
我有以下代码来剪辑我的AVAsset视频:Objective c 剪得更快,objective-c,avfoundation,avasset,Objective C,Avfoundation,Avasset,我有以下代码来剪辑我的AVAsset视频: AVURLAsset *asset = [AVURLAsset URLAssetWithURL:_url options:nil]; [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@",_url] error:nil]; AVAssetExportSession *exportSession = [[AVAssetExportSessio
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并重新加载需要一段时间。有没有可能使其更快?您可以使用
AVAssetExportPresetPassthrough
作为预设名称,而不是AVAssetExportPresetHighestQuality
。通过这种方式,您可能可以避免昂贵的转码。设置时间范围可能会妨碍某些格式,但值得尝试。您可以使用AVAssetExportPresetPassthrough
作为预设名称,而不是AVAssetExportPresetHighestQuality
。通过这种方式,您可能可以避免昂贵的转码。对于某些格式,设置时间范围可能会排除这种情况,但值得一试