不要轻易使用ffmpeg的audio_device_number来设置音频设备
最近项目中需要使用ffmpeg实现录音功能,使用的ffmpeg-3.4.4的库,根据源代码dshow.c中的定义
{ "audio_device_number", "set audio device number for devices with same name (starts at 0)", OFFSET(audio_device_number), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC },
在PC机存在两个麦克风设备的场合,添加一个[录音设备选择]对话框,可供用户选择。
打个比方:目前的PC机存在两个音频输入设备:
- 0:麦克风 (HD Webcam C270)
- 1:麦克风 (Realtek High Definition Audio)
备注:
- 0号采集设备可以采集音频与视频,不能播放音频;1号采集设备仅可以采集音频,可以播放音频。
- PC机设备播放设备只有1个,那就是:麦克风 (Realtek High Definition Audio),即为0号播放设备。
- 音频采集设备的序号与音频播放设备的序号很可能不一致。
如果指定 0号采集设备:麦克风 (HD Webcam C270)作为音频采集设备,简化代码如下:
char *pchDeviceName = "麦克风 (HD Webcam C270)";
AVInputFormat *m_pAudioInputFormat = av_find_input_format("dshow");
AVDictionary *options = NULL;
av_dict_set(&options, "audio_device_number", "", );
char str_device_gb2312_name[];
_snprintf(str_device_gb2312_name, sizeof(str_device_gb2312_name), "audio=%s", pchDeviceName);
char *pchUtfName = gb2312_to_utf8(str_device_gb2312_name);
int ret = -;
AVFormatContext *m_pAudioFmtCtx = avformat_alloc_context();
ret = avformat_open_input(&m_pAudioFmtCtx, pchUtfName, m_pAudioInputFormat, &options);
这时avformat_open_input函数成功,推测是因为0号音频采集设备与0号音频播放设备都存在所致。
如果指定 1号采集设备:麦克风 (Realtek High Definition Audio)作为音频采集设备,简化代码如下:
char *pchDeviceName = "麦克风 (Realtek High Definition Audio)";
AVInputFormat *m_pAudioInputFormat = av_find_input_format("dshow");
AVDictionary *options = NULL;
av_dict_set(&options, "audio_device_number", "", );
char str_device_gb2312_name[];
_snprintf(str_device_gb2312_name, sizeof(str_device_gb2312_name), "audio=%s", pchDeviceName);
char *pchUtfName = gb2312_to_utf8(str_device_gb2312_name);
int ret = -;
AVFormatContext *m_pAudioFmtCtx = avformat_alloc_context();
ret = avformat_open_input(&m_pAudioFmtCtx, pchUtfName, m_pAudioInputFormat, &options);
这时avformat_open_input函数失败原因是I/O fail,推测是因为1号音频采集设备存在但0号音频播放设备不存在所致。
此时的ffmpeg日志如下:
2019-12-10 13:57:21 076[ERR] Could not find audio only device with name [麦克风 (Realtek High Definition Audio)] among source devices of type audio.
2019-12-10 13:57:21 077[INF] Searching for audio device within video devices for 麦克风 (Realtek High Definition Audio)
2019-12-10 13:57:21 090[ERR] Could not find audio only device with name [麦克风 (Realtek High Definition Audio)] among source devices of type video.
解决方法如下(不指定音频设备序号,仅仅指定音频设备名称):
char *pchDeviceName = "麦克风 (Realtek High Definition Audio)";
AVInputFormat *m_pAudioInputFormat = av_find_input_format("dshow");
AVDictionary *options = NULL;
char str_device_gb2312_name[];
_snprintf(str_device_gb2312_name, sizeof(str_device_gb2312_name), "audio=%s", pchDeviceName);
char *pchUtfName = gb2312_to_utf8(str_device_gb2312_name);
int ret = -;
AVFormatContext *m_pAudioFmtCtx = avformat_alloc_context();
ret = avformat_open_input(&m_pAudioFmtCtx, pchUtfName, m_pAudioInputFormat, &options);
不要轻易使用ffmpeg的audio_device_number来设置音频设备的更多相关文章
- ffmpeg转码参数设置
ffmpeg用了很久了,也没有想写点什么. 刚接触ffmpeg也是有大量的不理解的地方,不过慢慢的了解多了基本上都是可以使用的. 本文主要介绍如何使用ffmpeg.exe进行转码.编译好的ffmpeg ...
- ffmpeg 速查手册
ref : http://linux.51yip.com/search/ffmpeg ffmpeg是一个源于Linux的工具软件,是FLV视频转换器,可以轻易地实现FLV向其它格式avi.asf. m ...
- [FFmpeg] ffmpeg参数详解
ffmpeg 参数语法 ffmpeg [[options][`-i' input_file]]... {[options] output_file}... 如果没有输入文件,那么视音频捕捉就会起作用. ...
- FFMPEG解码流程
FFMPEG解码流程: 1. 注册所有容器格式和CODEC: av_register_all() 2. 打开文件: av_open_input_file() 3. 从文件中提取流信息: av_f ...
- 【转】ffmpeg参数中文详细解释
感谢“大神”的无私奉献:http://blog.csdn.net/leixiaohua1020/article/details/15811977 a) 通用选项 -L license-h 帮助-fro ...
- ffmpeg视频格式转换(Java)
命令: 高品质: ffmpeg -i E:\input\a.wmv -ab 128 -acodec libmp3lame -ac 1 -ar 22050 -r 29.97 -qscale 4 -y E ...
- c# ffmpeg常用参数
c# ffmpeg常用参数 转换文件格式的同时抓缩微图: ffmpeg -i "test.avi" -y -f image2 -ss 8 -t 0.001 -s 350x240 ...
- ffmpeg命令学习
1.组成 程序:ffmpeg.ffplay.ffprobe.ffserverffmpeg:转码程序ffplay:播放程序ffserver:服务器程序 库:libavcodec.libavdevice. ...
- FFmpeg介绍及参数详细说明
FFmpeg是一个开源免费跨平台的视频和音频流方案,属于自由软件,采用LGPL或GPL许可证(依据你选择的组件).它提供了录制.转换以及流化音视频的完整解决方案.它包含了非常先进的音频/视频编解码库l ...
随机推荐
- 记录一些mysql常用命令
启动mysql (ubuntu系统, 以下都是Ubuntu上操作的命令) 这些命令都是可以在任何目录下执行的. # [sudo] 表示可加可不加sudo [sudo] /etc/init.d/mys ...
- 【luoguP5550】Chino的数列
题目背景 没有背景 我写不出来了qwq 题目描述 Chino给定了nn个数a_1...a_na1...an,给定常数s,m,她会轮流对这nn个数做k组操作,每组操作包含以下几步: 1.swap(a ...
- 【线性代数】2-7:转置与变换(Transposes and Permutation)
title: [线性代数]2-7:转置与变换(Transposes and Permutation) toc: true categories: Mathematic Linear Algebra d ...
- 【强化学习】1-1-2 “探索”(Exploration)还是“ 利用”(Exploitation)都要“面向目标”(Goal-Direct)
title: [强化学习]1-1-2 "探索"(Exploration)还是" 利用"(Exploitation)都要"面向目标"(Goal ...
- ida 下载
链接:https://pan.baidu.com/s/1Rs2UOSfroBGf_MIkJv0cGw 提取码:kjqd 官网:https://www.hex-rays.com/updida.shtml
- OpenDayLight安装Features
OpenDayLight 0.4.4-Beryllium-SR4 opendaylight-user@root>feature:install odl-restconf opendaylight ...
- Oracle用户被锁解决方法
.查看用户的proifle是哪个,一般是default: sql>SELECT username,PROFILE FROM dba_users; .查看指定概要文件(如default)的密码有效 ...
- Linux dirname 和 basename
[参考文章]:Linux shell - `dirname $0` 定位到运行脚本的相对位置 [参考文章]:Linux命令之basename使用 1. dirname $0 获取脚本文件所在的目录信息 ...
- shell [ ] 和 [[ ]] 区别
[参考文章]:shell if [[ ]]和[ ]区别 || && [参考文章]:Shell test 命令 1. [ ] 和 test test 等同于 [ ] 可用于判断某个条件 ...
- CPU分支预测器
两篇结合就ok啦 1.https://www.jianshu.com/p/be389eeba589 2.https://blog.csdn.net/edonlii/article/details/87 ...