我正在实现AVAssetExportSession,以修剪一个在线视频,但总是返回失败。
以下是我的实现:
NSString *url = @"http://www.ebookfrenzy.com/ios_book/movie/movie.mov";
NSURL *fileURL = [NSURL URLWithString:url];
AVAsset *asset = [AVAsset assetWithURL:fileURL];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
NSURL *exportUrl = [NSURL fileURLWithPath:[documentsDirectory stringByAppendingPathComponent:@"export.m4a"]];
exportSession.outputURL = exportUrl;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
CMTime time = CMTimeMake(1, 10);
exportSession.timeRange = CMTimeRangeMake(kCMTimeZero, time);
[exportSession exportAsynchronouslyWithCompletionHandler:^(void) {
switch (exportSession.status)
{
case AVAssetExportSessionStatusCompleted:
/*expor is completed*/
NSLog(@"Completed!!");
break;
case AVAssetExportSessionStatusFailed:
NSLog(@"failed!!");
/*failed*/
break;
default:
break;
}
}];你们知道为什么会发生这种事或者我做错了什么吗?
发布于 2015-10-06 20:40:28
您正在尝试使用远程URL创建一个AVAsset,并且在开始导出之前,您需要知道资产已经加载。
AVAsset符合AVAsynchronousKeyValueLoading协议,这意味着一旦值发生变化,您就可以观察tracks密钥并启动导出:
NSURL *myURL = [NSURL URLWithString:myMovieURLString];
AVAsset *asset = [AVAsset assetWithURL:myURL];
__weak typeof(self) weakSelf = self;
[asset loadValuesAsynchronouslyForKeys:@[@"tracks"] completionHandler:^{
//Error checking here - make sure there are tracks
[weakSelf exportAsset:asset];
}];然后,您可以将导出代码放在单独的方法中:
- (void)exportAsset:(AVAsset *)asset {
//Your export code here
}发布于 2016-06-28 08:48:33
documentsDirectory应该是一条退出路径。如果没有,exportSession.status将等于AVAssetExportSessionStatusFailed
https://stackoverflow.com/questions/32930885
复制相似问题