今天合成视频的时候遇到了这个问题,报错的内容是
-[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array
出错的代码是
[AudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, item.asset.duration) ofTrack:[[item.asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:tmpTime error:nil];
乍一看之下会发现根本没有数组啊,结果点进去发现原来是track的数组取不到值
[AudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, item.asset.duration) ofTrack:([arr count]>0)?[arr objectAtIndex:0]:nil atTime:tmpTime error:nil];
如此即可解决,并且合并多个mov也可以取出音轨
参考:http://*.com/questions/17064382/with-avmutablecomposition-video-creation-issue
解决取出音轨[[asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] 报错的问题