我想使用AVPlayer缓存渐进式下载的视频。如何将AVPlayer的项目保存到磁盘?我正在尝试在播放器的当前项目(已完全加载)上使用AVAssetExportSession。这段代码给我返回了“AVAssetExportSessionStatusFailed(操作无法完成)”:
AVAsset *mediaAsset = self.player.currentItem.asset;
AVAssetExportSession *es = [[AVAssetExportSession alloc] initWithAsset:mediaAsset presetName:AVAssetExportPresetLowQuality];
NSString *outPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"out.mp4"];
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:outPath error:NULL];
es.outputFileType = @"com.apple.quicktime-movie";
es.outputURL = [[[NSURL alloc] initFileURLWithPath:outPath] autorelease];
NSLog(@"exporting to %@",outPath);
[es exportAsynchronouslyWithCompletionHandler:^{
NSString *status = @"";
if( es.status == AVAssetExportSessionStatusUnknown ) status = @"AVAssetExportSessionStatusUnknown";
else if( es.status == AVAssetExportSessionStatusWaiting ) status = @"AVAssetExportSessionStatusWaiting";
else if( es.status == AVAssetExportSessionStatusExporting ) status = @"AVAssetExportSessionStatusExporting";
else if( es.status == AVAssetExportSessionStatusCompleted ) status = @"AVAssetExportSessionStatusCompleted";
else if( es.status == AVAssetExportSessionStatusFailed ) status = @"AVAssetExportSessionStatusFailed";
else if( es.status == AVAssetExportSessionStatusCancelled ) status = @"AVAssetExportSessionStatusCancelled";
NSLog(@"done exporting to %@ status %d = %@ (%@)",outPath,es.status, status,[[es error] localizedDescription]);
}];
我该如何成功导出?我正在尝试将mediaAsset复制到AVMutableComposition中,但是也没有太多的成功经验。
谢谢!
附注:以下是一些其他人尝试实现相同目标的问题(但使用MPMoviePlayerController):
- 在MPMoviePlayerController中缓存渐进式下载的内容 - 同时流式传输和保存视频? - 在MPMoviePlayerController成功预加载后将视频缓存在磁盘中