ffmpeg 命令
windows 环境
查看设备
ffmpeg -list_devices true -f dshow -i dummy
采集麦克风代码
//1. init
avdevice_register_all();
//avformat_network_init();
//2.获取windows采集数据所支持的格式(dshow)
const AVInputFormat *fmt = av_find_input_format("dshow");
int ret = 0;
AVPacket pkt;
//3.定义录制音屏格式上下文。
AVFormatContext *ctx = nullptr;
//内装麦克风 (Conexant SmartAudio HD)
// 麦克风 (Realtek(R) Audio)
//const char *audio_device = "audio=内装麦克风 (Conexant SmartAudio HD)";
const char *audio_device = "audio=麦克风 (Realtek(R) Audio)";
ret = avformat_open_input(&ctx, audio_device, fmt, nullptr);
if(ret != 0)
{
qDebug() << ret << "打开设备失败";
return;
}
// 4.定义一个文件用来保存所采集的音频设备
QFile file("./test.pcm");
file.open(QIODevice::WriteOnly);
if(!file.isOpen()){
qDebug() << "file open fialed";
avformat_close_input(&ctx);
return;
}
//5.采集音频数据 ffplay -ar 4100 -ac 2 -f s16le test.pcm
while( !status_flag && !av_read_frame(ctx, &pkt)){
file.write((const char*)pkt.data, pkt.size);
}
//6.释放资源
avformat_close_input(&ctx);
file.close();
使用命名播放
ffplay -ar 4100 -ac 2 -f s16le test.pcm