ffmpeg虽然是跨平台库,mac和windows还是有区别的,这里介绍下mac如何打开audo并采集。
1.查找解码器
_input_fmt = av_find_input_format("avfoundation");
2.打开设备
_fmt_ctx = avformat_alloc_context();
ret = avformat_open_input(&_fmt_ctx, device_name.c_str(), _input_fmt, NULL);
if (ret != 0) {
error = AE_FFMPEG_OPEN_INPUT_FAILED;
break;
}
这需要注意的是设备名字,在window我们可能输入的:audio = xxxxxx,mac不一样,mac这里的设备包含video和audio类似"0:1",输入的是屏幕index和audio index。直接输入设备名字打开是失败的,设备index和可以根据ffmpeg命令获得:
ffmpeg -f avfoundation -list_devices true -i ""
这里会列出所有avfoundation 设备,我电脑显示如下:
liuzhaomingdeMacBook-Pro:Recorder liuzhaoming$ ffmpeg -f avfoundation -list_devices true -i ""
ffmpeg version N-100493-gc720286 Copyright (c) 2000-2020 the FFmpeg developers
built with Apple clang version 11.0.3 (clang-1103.0.32.62)
configuration: --enable-libx264 --enable-gp

本文介绍了如何在Mac上利用ffmpeg库打开和采集音频设备。首先,通过av_find_input_format找到解码器,然后使用avformat_open_input打开设备,注意设备名称应为屏幕索引和音频索引的组合,例如0:1。通过ffmpeg命令获取设备列表,并根据设备序号指定打开哪个设备。接着,创建线程读取和解码数据。该过程适用于音频和视频设备的采集。
最低0.47元/天 解锁文章
672

被折叠的 条评论
为什么被折叠?



