我的大脑感觉就像炒鸡蛋……我正在尝试将视频剪辑合并在一起。我将每个剪辑 URL 存储在 NSMutableArray (arrayClipURL) 中,这一切都很好。当我在调试控制台中打印 timeRanges 和轨道(都是 NSMutableArrays)时,一切都检查出来了,这意味着 for 循环正在完成它的工作。我不断收到异常错误:' * -[__NSArrayM insertObject:atIndex:]: object cannot be nil'。
我抛出了一个异常断点,它在下面的最后一行中断。我无法弄清楚,因为 timeRanges 和 track 都不是零……我可以在调试控制台中打印它们,并在断线之前直接看到它们。
composition = [[AVMutableComposition composition] init];
composedTrack = [[AVMutableCompositionTrack alloc] init];
composedTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
NSMutableArray * timeRanges = [[NSMutableArray alloc] initWithCapacity:arrayClipURL.count];
NSMutableArray * tracks = [[NSMutableArray alloc] initWithCapacity:arrayClipURL.count];
for (int i=0; i<[arrayClipURL count]; i++){
AVURLAsset *assetClip = [[AVURLAsset alloc] initWithURL:[arrayClipURL objectAtIndex:i] options:nil];
AVAssetTrack *clipTrack = [[AVAssetTrack alloc] init];
clipTrack = [[assetClip tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
[timeRanges addObject:[NSValue valueWithCMTimeRange:CMTimeRangeMake(kCMTimeZero, assetClip.duration)]];
[tracks addObject:clipTrack];
}
debug(@"timeranges: %@",timeRanges);
debug(@"tracks: %@",tracks);
[composedTrack insertTimeRanges:timeRanges ofTracks:tracks atTime:kCMTimeZero error:nil];
我需要一些资深的帮助:(知道可能是什么导致了这个问题吗?
编辑:这是 2 个数组在控制台中打印的样子。我唯一能想到的可能是 CMTimeRange 或 AVAssetTrack 没有在数组中正确格式化???我不知道。只是认为在抛出异常时查看它实际尝试插入的内容可能会有所帮助。
2013-02-18 13:18:20.811 app[5242:907] [AVCaptureManager.m:401] timeranges array: (
"CMTimeRange: {{0/1 = 0.000}, {498/600 = 0.830}}",
"CMTimeRange: {{0/1 = 0.000}, {556/600 = 0.927}}"
)
2013-02-18 13:18:20.812 app[5242:907] [AVCaptureManager.m:402] tracks array: (
"<AVAssetTrack: 0x220c21a0, trackID = 1, mediaType = vide>",
"<AVAssetTrack: 0x1cdec820, trackID = 1, mediaType = vide>"
)