段错误
来源:2-6 巩固vim的简单使用(熟练可跳过)

wangkai8515
2023-06-09
打开音频设备段错误是怎么回事?
void open(){
int ret = 0;
char errors[1024] = {0};
//context
AVFormatContext *fmt_ctx =NULL ;
//paket
int count = 0;
AVPacket pkt;
//create file
char *out = "./audio.pcm";
FILE *outfile = fopen(out,"wb+");
char *devicename = "hw:0,0";
//register audio device
avdevice_register_all();
//get format
AVInputFormat *iformat = av_find_input_format("alsa");
//open audio
if( (ret = avformat_open_input(&fmt_ctx, devicename, iformat, NULL)) < 0)
{
av_strerror(ret, errors, 1024);
printf("Failed to open audio device, [%d]%s\n", ret, errors);
return;
};
av_init_packet(&pkt);
//read data form audio
while(ret = (av_read_frame(fmt_ctx, &pkt))== 0&&
count++ < 500) {
av_log(NULL, AV_LOG_INFO, "pkt size is %d(%p), count=%d\n", pkt.size,pkt.data, count);
fwrite(pkt.data, 1, pkt.size, outfile);
fflush(outfile);
av_packet_unref(&pkt);//release pkt
}
fclose(outfile);
avformat_close_input(&fmt_ctx);//releas ctx
return;
}
int main(){
open();
return 0;
}
写回答
1回答
-
李超
2023-06-09
在什么操作系统上?在那行crash 的?
042023-06-09
相似问题