【发布时间】:2021-08-07 15:43:59
【问题描述】:
我正在使用 libav/ffmpeg 编写程序来下载互联网广播流并使用 alsa 在声卡上播放。
我已经设法下载流并提取数据包和帧。
我遇到了必须调用的 av_write_header() 函数(根据 https://www.ffmpeg.org/doxygen/3.2/group__lavf__encoding.html#details)的问题。它崩溃并给我以下错误:
[alsa @ 0x55d7ba32e580] 不支持样本格式 0x15001
数字 0x15001 是十进制的 86017,这是该流使用的 MP3 格式 (AV_CODEC_ID_MP3) 的枚举 AVCodecID 中的索引。示例格式的索引为 3。我不明白为什么 libav 解析标头错误。
这是我负责配置输出的部分代码:
avdevice_register_all();
AVOutputFormat *output = av_guess_format("alsa",NULL,NULL);
AVFormatContext *outputFormatContext = avformat_alloc_context();
outputFormatContext->oformat = output;
outputFormatContext->flags = AVFMT_NOFILE;
AVStream *stream = avformat_new_stream(outputFormatContext,NULL);
AVCodecParameters *oCodecParameters = avcodec_parameters_alloc();
ret = avcodec_parameters_copy(oCodecParameters,iCodecParameters);
if(ret < 0){
printf("avformat_parameters_copy\n");
exit(0);
}
stream->codecpar = oCodecParameters;
if(avformat_write_header(outputFormatContext,NULL)<0){
dumpParameters(stream->codecpar);
printf("avformat_write_header\n");
exit(0);
}
【问题讨论】: