首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更快地切割AVAsset

更快地切割AVAsset
EN

Stack Overflow用户
提问于 2016-08-25 18:13:55
回答 1查看 135关注 0票数 1

我有这样的代码来剪切我的AVAsset视频:

代码语言:javascript
复制
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并重新加载需要一段时间。能让它更快吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-25 21:30:00

您可以使用AVAssetExportPresetPassthrough作为预先设置的名称,而不是AVAssetExportPresetHighestQuality。这样您可能可以避免昂贵的代码转换。设置一个时间范围可能会排除某些格式的这种情况,但值得一试。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39152153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档