FFmpeg中的channels 和 channel_layout

channels 和 channel_layout 是啥

channels  为 音频的 通道数 1 2 3 4 5.....
channel_layout  为音频 通道格式类型 如 单通道 双通道 .....

相互之间的获取

av_get_channel_layout_nb_channels()
av_get_default_channel_layout()

对应关系

channel_layout_map[]
	{ "mono",        1,  AV_CH_LAYOUT_MONO },
    { "stereo",      2,  AV_CH_LAYOUT_STEREO },
    { "2.1",         3,  AV_CH_LAYOUT_2POINT1 },
    { "3.0",         3,  AV_CH_LAYOUT_SURROUND },
    { "3.0(back)",   3,  AV_CH_LAYOUT_2_1 },
    { "4.0",         4,  AV_CH_LAYOUT_4POINT0 },
    { "quad",        4,  AV_CH_LAYOUT_QUAD },
    { "quad(side)",  4,  AV_CH_LAYOUT_2_2 },
    { "3.1",         4,  AV_CH_LAYOUT_3POINT1 },
    { "5.0",         5,  AV_CH_LAYOUT_5POINT0_BACK },
    { "5.0(side)",   5,  AV_CH_LAYOUT_5POINT0 },
    { "4.1",         5,  AV_CH_LAYOUT_4POINT1 },
    { "5.1",         6,  AV_CH_LAYOUT_5POINT1_BACK },
    { "5.1(side)",   6,  AV_CH_LAYOUT_5POINT1 },
    { "6.0",         6,  AV_CH_LAYOUT_6POINT0 },
    { "6.0(front)",  6,  AV_CH_LAYOUT_6POINT0_FRONT },
    { "hexagonal",   6,  AV_CH_LAYOUT_HEXAGONAL },
    { "6.1",         7,  AV_CH_LAYOUT_6POINT1 },
    { "6.1",         7,  AV_CH_LAYOUT_6POINT1_BACK },
    { "6.1(front)",  7,  AV_CH_LAYOUT_6POINT1_FRONT },
    { "7.0",         7,  AV_CH_LAYOUT_7POINT0 },
    { "7.0(front)",  7,  AV_CH_LAYOUT_7POINT0_FRONT },
    { "7.1",         8,  AV_CH_LAYOUT_7POINT1 },
    { "7.1(wide)",   8,  AV_CH_LAYOUT_7POINT1_WIDE },
    { "octagonal",   8,  AV_CH_LAYOUT_OCTAGONAL },
    { "downmix",     2,  AV_CH_LAYOUT_STEREO_DOWNMIX, },


  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个使用 FFmpeg 库的示例: 1. 将 FFmpeg 库文件复制到 Android 项目的 libs 目录下。假设我们将 libavcodec.so、libavformat.so、libavutil.so、libswscale.so、libswresample.so 这些库文件放在 libs 目录下。 2. 在项目的 build.gradle 文件添加以下代码,将 FFmpeg 库文件作为本地依赖库引入: ```groovy dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.so']) } ``` 3. 在需要使用 FFmpeg 库的代码,使用 System.loadLibrary() 方法加载 FFmpeg 库。假设我们需要使用 libavcodec.so 和 libavformat.so,那么我们可以在 MainActivity.java 添加以下代码: ```java public class MainActivity extends AppCompatActivity { static { System.loadLibrary("avutil"); System.loadLibrary("avcodec"); System.loadLibrary("avformat"); } // ... } ``` 需要根据实际情况加载所需的 FFmpeg 库文件。 4. 在使用 FFmpeg 库的代码,调用 FFmpeg 库的函数。以下是一个简单的示例,使用 FFmpeg 库打开一个视频文件并获取视频信息: ```java public class MainActivity extends AppCompatActivity { static { System.loadLibrary("avutil"); System.loadLibrary("avcodec"); System.loadLibrary("avformat"); } private static final String TAG = "MainActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 打开视频文件 AVFormatContext formatContext = new AVFormatContext(null); int ret = avformat_open_input(formatContext, "/sdcard/test.mp4", null, null); if (ret != 0) { Log.e(TAG, "avformat_open_input failed: " + ret); return; } // 获取视频信息 ret = avformat_find_stream_info(formatContext, null); if (ret < 0) { Log.e(TAG, "avformat_find_stream_info failed: " + ret); return; } // 输出视频信息 Log.i(TAG, "format: " + formatContext.iformat.long_name.getString()); for (int i = 0; i < formatContext.nb_streams; i++) { AVStream stream = formatContext.streams[i]; AVCodecParameters codecParameters = stream.codecpar; Log.i(TAG, "stream " + i + " type: " + codecParameters.codec_type); Log.i(TAG, "stream " + i + " codec name: " + avcodec_get_name(codecParameters.codec_id)); Log.i(TAG, "stream " + i + " duration: " + stream.duration); Log.i(TAG, "stream " + i + " bit rate: " + codecParameters.bit_rate); Log.i(TAG, "stream " + i + " width: " + codecParameters.width); Log.i(TAG, "stream " + i + " height: " + codecParameters.height); Log.i(TAG, "stream " + i + " sample rate: " + codecParameters.sample_rate); Log.i(TAG, "stream " + i + " channels: " + codecParameters.channels); Log.i(TAG, "stream " + i + " channel layout: " + codecParameters.channel_layout); } // 关闭视频文件 avformat_close_input(formatContext); } } ``` 需要注意的是,以上代码仅供参考,实际使用时需要根据 FFmpeg 库的版本和编译选项进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值