ffmpeg录制音频 命令行与C++实现 |
您所在的位置:网站首页 › mp4音频怎么录制 › ffmpeg录制音频 命令行与C++实现 |
关于音视频,看了很多的博客,发现都很难正确的打开设备与录制。然后就自己瞎搞,突然发现能正确的录制与打开了,故此记录一下。 一、官方wiki https://trac.ffmpeg.org/wiki/Capture/ALSA 提取一句关于音频录制的命令: ffmpeg -f alsa -channels 1 -sample_rate 44100 -i hw:0 -t 30 out.wavlinux选择alsa的设备,mac上是avfoundation,sample_rate指的是采样率,channels是通道数,视系统而定,笔者这里选择单通道会报错,错误如下: [alsa @ 0x55b0f9f49780] cannot set channel count to 1 (Invalid argument) hw:0: Input/output error然后我修改成了双通道就ok了。这里还有一个坑就是插上耳机的时候,打开系统设置可以查看到相关的状态 主函数文件 #include #include "av.h" using namespace std; int main() { // register device avdevice_register_all(); // set logger level av_log_set_level(AV_LOG_DEBUG); // get input device format AVInputFormat *format = av_find_input_format("alsa"); // init context AVFormatContext *fmt_ctx = nullptr; std::string deviceName = "hw:0"; AVDictionary *options = nullptr; // open audio device int ret = avformat_open_input(&fmt_ctx, deviceName.c_str(), format, &options); if (ret ret = av_read_frame(fmt_ctx, &ptk); // write file fwrite(ptk.data,ptk.size,1,out); std::cout |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |