void ffmpegTest()
{
//audio format context
//save whole audio context information
AVFormatContext *avfcontext;
//save error information
char errorinfo[1024];
AVDictionary *options = NULL;
// ret < 0 represent failing to open device
int ret = 0;
//the order to list local device
//or to use device manager to find local device
//ffmpeg -list_devices true -f dshow -i dummy
//format for mac : [[video device] : [ audio device]]
//format for windows : [video[or audio]=麦克风(Realtek(R) Audio)]
//need to format devicename to utf-8
char devicename[] = "audio=麦克风阵列(Realtek High Definition Audio)";
//register all audio device
avdevice_register_all();
//get audio input format
/*
avfoundation: mac
dshow: windows
alsa: linux
*/
AVInputFormat *aviformat= av_find_input_format("dshow");
/*
open audio input stream
@param AVFormatContext :
@param char url : open audio from url
@param AVInputFormat :
@param AVDictionary : argument to control device property
*/
//open
if ((ret = avformat_open_input(&avfcontext, devicename, aviformat, &options)) < 0)
{
av_strerror(ret,errorinfo,1024);
printf("Failed to open audio device,[%d]%s\n", ret, errorinfo);
return;
}
}