[英]How can I record an audio from USB audio device using C++ with ffmpeg on Linux?
如何在Linux上使用帶有ffmpeg的C ++從USB音頻設備錄制音頻? 我有以下代碼。 但是我不知道如何在avformat_open_input函數中設置'url'的參數。 有人可以提供協助嗎? 非常感激。
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 }
您是否讀過這個對音頻和視頻進行解復用和解碼的示例? 通過僅使用音頻部分並過濾掉不需要的部分,您應該能夠錄制音頻。
另外,執行時會得到什么
arecord -l
在航站樓? 鑒於你得到類似
card x: USB audio
嘗試提供“ hw:x”作為輸入,其中x是arecord -l命令給定的卡號。 在我的情況下,USB麥克風是卡1,因此我將“ hw:1”作為輸入輸入FFmpeg。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.