avformat_open_input(&ps, "default", NULL, NULL)返回值为-2。

AVFormatContext *ps=avformat_alloc_context();;
AVDictionary *options=NULL;
char erros[1024]={0};
char *devicename="default";
int ret=0;

int count=0;
AVPacket pkt;
av_init_packet(&pkt);

av_log_set_level(AV_LOG_DEBUG);
av_register_all();
avdevice_register_all();
avformat_network_init();
printf("this is func\n");
AVInputFormat *iformat=av_find_input_format("alsa");
av_dict_set(&options, "sample_rate", "44100", 0);
av_dict_set(&options, "channels", "1", 0);
ret=avformat_open_input(&ps, devicename, NULL, NULL);

printf("this is func\n");
if(ret<0){
    av_strerror(ret, erros,1024);
    printf("failed to open audio device,[%d] %s\n",ret,erros);
    return;
}

https://blog.csdn.net/Bobsweetie/article/details/50935779