简体   繁体   English

如何在Linux上使用带有ffmpeg的C ++从USB音频设备录制音频?

[英]How can I record an audio from USB audio device using C++ with ffmpeg on Linux?

How can I record an audio from USB audio device using C++ with ffmpeg on Linux? 如何在Linux上使用带有ffmpeg的C ++从USB音频设备录制音频? I have the following code. 我有以下代码。 But I have no idea how to set the parameter of 'url' in the function of avformat_open_input. 但是我不知道如何在avformat_open_input函数中设置'url'的参数。 Could assistance be provided by anybody? 有人可以提供协助吗? Much appreciated. 非常感激。

   27     av_register_all();
   28     avdevice_register_all();
   29
   30     //pAudioInputFmt =av_find_input_format("dshow");
   31     pAudioInputFmt =av_find_input_format("alsa");
   32     //assert(pAudioInputFmt != NULL);
   33     if (!(pAudioInputFmt != NULL))
   34     {
   35         printf("Error %s %d\n", __FILE__, __LINE__);
   36         char ch = cin.get();
   37         cout << "ch = "<< ch << endl;
   38         return (-1);
   39     }
   40
   41     // I have no idear how to set the second parameter on Linux.
   42     if (!(avformat_open_input(&pFmtCtx, "=Device)", pAudioInputFmt,NULL) == 0))
   43     {
   44         printf("Error %s %d\n", __FILE__, __LINE__);
   45         system("pause");
   46         return (-1);
   47     }

Have you read this example of demuxing and decoding audio and video? 您是否读过这个对音频和视频进行解复用和解码的示例? By using only the audio part and filtering out what you don't need, you should be able to record audio. 通过仅使用音频部分并过滤掉不需要的部分,您应该能够录制音频。

Also, what do you get when executing 另外,执行时会得到什么

arecord -l

in the terminal? 在航站楼? Given that you get something like 鉴于你得到类似

card x: USB audio

try to give "hw:x" as the input, where x is the number of the card given by the arecord -l command. 尝试提供“ hw:x”作为输入,其中x是arecord -l命令给定的卡号。 In my case the USB microphone is card 1, so I give "hw:1" as the input to FFmpeg. 在我的情况下,USB麦克风是卡1,因此我将“ hw:1”作为输入输入FFmpeg。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM