经过上一步的项目配置,视频正常播放,但是音频播放出现问题,下文给出作者修改的过程
错误1

根据No more combinations to try, audio open failed
错误,定位到ffplay.c如下函数
cpp
while (!(audio_dev = SDL_OpenAudioDevice(NULL, 0, &wanted_spec, &spec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_CHANNELS_CHANGE))) {
av_log(NULL, AV_LOG_WARNING, "SDL_OpenAudio (%d channels, %d Hz): %s\n",
wanted_spec.channels, wanted_spec.freq, SDL_GetError());
wanted_spec.channels = next_nb_channels[FFMIN(7, wanted_spec.channels)];
if (!wanted_spec.channels) {
wanted_spec.freq = next_sample_rates[next_sample_rate_idx--];
wanted_spec.channels = wanted_nb_channels;
if (!wanted_spec.freq) {
av_log(NULL, AV_LOG_ERROR,
"No more combinations to try, audio open failed\n");
return -1;
}
}
wanted_channel_layout = av_get_default_channel_layout(wanted_spec.channels);
}
-
本函数作用是打开音频设备播放音频数据,经过调试得到
!wanted_spec.freq)
值为0,因此报错:No more combinations to try, audio open failed\n
-
向上找:
wanted_spec.freq = next_sample_rates[next_sample_rate_idx--];
,判断是next_sample_rate_idx
值出现问题 -
再次定位如下代码:
cppwhile (next_sample_rate_idx && next_sample_rates[next_sample_rate_idx] >= wanted_spec.freq) next_sample_rate_idx--;
这个函数作用是从采样率数组中找到第一个不大于传入参数wanted_sample_rate的值
此时,
wanted_spec.freq=44100
,next_sample_rate_idx = 4
,next_sample_rates = {0, 44100, 48000, 96000, 192000}
函数返回时,
next_sample_rate_idx = 0
,从而导致wanted_spec.freq = 0
,最终报错修改:大于等于号变为大于号
arduinowhile (next_sample_rate_idx && next_sample_rates[next_sample_rate_idx] > wanted_spec.freq)
此时,
next_sample_rate_idx = 1
,wanted_spec.freq = 44100
错误2

这条错误消息表明当你尝试使用 SDL 打开音频设备时,发生了一个错误,特别是在使用 XAudio2 API 时。
XAudio2 是 Microsoft DirectX SDK 中的一部分,它是用于在 Windows 平台上进行高性能音频处理和音频渲染的音频库。
经过chatgpt和查阅资料,解决方案是:添加CoInitialize(NULL)
在 Windows 环境中初始化 COM 。
步骤:
1 在
read_phtread()
函数内添加代码
scssCoInitialize(NULL);
2
ffplay.c
包含头文件
arduino#include <objbase.h>
3
.pro
文件中添加lib库
shell$$PWD/Ole32.Lib
- 使用everything查找
Ole32.Lib
- 项目是32下,因此选取的是x86的lib文件
- 将lib放入项目目录下(不是运行目录,运行目录下存放的是dll动态库)

修改完以上两个错误,声音正常播放!