解决Value of type ‘AVCodecContext‘ has no member ‘channels‘ 的问题

在 FFmpeg 7.1 中,AVCodecContextchannelschannel_layout 字段已经被移除,取而代之的是 AVChannelLayout 结构。因此,代码需要进行调整以适应新的 API。

以下是如何正确设置 AVCodecContextAVCodecParameters 的方法。


1. 问题分析

在 FFmpeg 7.1 中:

  • AVCodecContext.channels 被移除,通道数现在由 AVChannelLayout 结构管理。
  • AVCodecContext.channel_layout 也被移除,通道布局同样由 AVChannelLayout 结构管理。
  • AVChannelLayout 是一个新的结构,用于更灵活地表示音频的通道布局。

因此,以下代码需要修改:

codecContext.pointee