首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在AudioLayout中检测AVAssetTrack

在AudioLayout中检测AVAssetTrack
EN

Stack Overflow用户
提问于 2022-03-22 11:11:26
回答 1查看 53关注 0票数 0

我需要检测来自AVAssetTrack的频道数量和音频格式(交错或非交织)。我尝试了下面的代码来检测通道的数量。从代码中可以看出,有两种检测通道数目的方法。我想知道哪一个更可靠和正确,还是没有(不管音频格式)?

代码语言:javascript
运行
复制
  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) 
        }

}

我不知道如何获得音频格式的细节(交错或非交织)。在这方面寻求帮助。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71571083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档