我需要检测来自AVAssetTrack的频道数量和音频格式(交错或非交织)。我尝试了下面的代码来检测通道的数量。从代码中可以看出,有两种检测通道数目的方法。我想知道哪一个更可靠和正确,还是没有(不管音频格式)?
if let formatDescriptions = track.formatDescriptions as? [CMAudioFormatDescription],
let audioFormatDesc = formatDescriptions.first,
let asbd = CMAudioFormatDescriptionGetStreamBasicDescription(audioFormatDesc)
{
//First way to detect number of channels
numChannels = asbd.pointee.mChannelsPerFrame
var aclSize:size_t = 0
var currentChannelLayout:UnsafePointer<AudioChannelLayout>? = nil
currentChannelLayout = CMAudioFormatDescriptionGetChannelLayout(audioFormatDesc, sizeOut: &aclSize)
if let currentChannelLayout = currentChannelLayout, aclSize > 0 {
let channelLayout = currentChannelLayout.pointee
//second way of detecting number of channels
numChannels = AudioChannelLayoutTag_GetNumberOfChannels(channelLayout.mChannelLayoutTag)
}
}我不知道如何获得音频格式的细节(交错或非交织)。在这方面寻求帮助。
https://stackoverflow.com/questions/71571083
复制相似问题