Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 剪得更快_Objective C_Avfoundation_Avasset - Fatal编程技术网

Objective c 剪得更快

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

我有以下代码来剪辑我的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并重新加载需要一段时间。有没有可能使其更快?

您可以使用
AVAssetExportPresetPassthrough
作为预设名称,而不是
AVAssetExportPresetHighestQuality
。通过这种方式,您可能可以避免昂贵的转码。设置时间范围可能会妨碍某些格式,但值得尝试。

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