2016-08-25 9 views
1

У меня есть этот код, чтобы сократить мой AVAsset Видео:Cut 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 и перезагрузить его. Возможно ли это сделать быстрее?

ответ

0

Вы можете использовать AVAssetExportPresetPassthrough в качестве своего имени предварительной настройки, а не AVAssetExportPresetHighestQuality. Возможно, вы сможете избежать дорогого транскодирования. Установка временного диапазона может исключить это для некоторых форматов, но стоит попробовать.

Смежные вопросы