ffplay播放没有声音SDL_OpenAudio (2 channels, 44100 Hz): WASAPI can’t initialize audio client
作者:互联网
**windows使用ffplay播放没有声音**
ffplay播放没有声音SDL_OpenAudio (2 channels, 44100 Hz): WASAPI can’t initialize audio client
在window7 64bit下安装了ffmpeg,然后用ffplay命令播放声音时发生这个错误:
SDL_OpenAudio (2 channels, 44100 Hz): WASAPI can’t initialize audio client
那么只能播放视频图像而不能播放视频声音。
在SO上找到解决方法:resolve
只要设置环境一个变量SDL_AUDIODRIVER=directsound或者winmm即可,那么就可以播放了。原因不清楚,可能跟sdl库有关吧
写一个start.bat加入下面代码:
set SDL_AUDIODRIVER=directsound
使用mingw环境终端播放时,可以在msys.bat文件第一行中写入:
set SDL_AUDIODRIVER=directsound
ffmpeg官网解决方案
@转载 http://trac.ffmpeg.org/ticket/6891
#6891 new defect
FFplay: WASAPI can’t initialize audio client (zeranoe’s FFmpeg 3.4 MS Windows binaries)
Summary of the bug:
When I try to play an audio file with ffplay, it fails with errors such as this one:
SDL_OpenAudio (1 channels, 48000 Hz): WASAPI can’t initialize audio client: No se ha llamado a CoInitialize.
How to reproduce:
C:\Users\Public\Documents>ffplay.exe C:\Users\Public\Documents\test.mp3
ffplay version 3.4 Copyright © 2003-2017 the FFmpeg developers
built with gcc 7.2.0 (GCC)
configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-bzlib --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-cuda --enable-cuvid --enable-d3d11va --enable-nvenc --enable-dxva2 --enable-avisynth --enable-libmfx
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
Input #0, mp3, from ‘C:\Users\Public\Documents\test.mp3’: 0B f=0/0
Metadata:
encoder : Lavf53.32.100
Duration: 01:00:00.26, start: 0.000000, bitrate: 128 kb/s
Stream #0:0: Audio: mp3, 48000 Hz, stereo, s16p, 128 kb/s
SDL_OpenAudio (2 channels, 48000 Hz): WASAPI can’t initialize audio client: No se ha llamado a CoInitialize.
SDL_OpenAudio (1 channels, 48000 Hz): WASAPI can’t initialize audio client: No se ha llamado a CoInitialize.
SDL_OpenAudio (2 channels, 44100 Hz): WASAPI can’t initialize audio client: No se ha llamado a CoInitialize.
SDL_OpenAudio (1 channels, 44100 Hz): WASAPI can’t initialize audio client: No se ha llamado a CoInitialize.
No more combinations to try, audio open failed
Failed to open file ‘C:\Users\Public\Documents\test.mp3’ or configure filtergraph
nan : 0.000 fd= 0 aq= 0KB vq= 0KB sq= 0B f=0/0
Last working version: ffplay from ffmpeg-20170921-183fd30-win32-shared
There is a workaround to this issue, according to this question at stackoverflow:
A workaround is to specify an alternate output driver.
Set SDL_AUDIODRIVER environment variable value to the
driver you want to use. Under windows 7, directsound
and winmm both solved my issue.
And there is a proposed fix to this issue at ffmpeg.zeranoe.com forum:
Re: I can’t run ffplay because of errors of SDL_OpenAudio
Post by jackyxinli » Wed Nov 29, 2017 2:43 am
I find a new method to resolve this problem, the ffplay
not call CoInitialize according to error message. So,
add code to call CoInitialize, ffplay can work. And the
same time, I checked SDL2’s source code, the WASAPI
module doesn’t set member ProvidesOwnCallbackThread, so
SDL2 should call CoInitialize before open audio device.
But no idea why ffplay gives us this error message.
here is my modification look like.
#ifdef _WIN32
#include <windows.h>
#endif
static int audio_open(void *opaque, int64_t wanted_channel_layout, int wanted_nb_channels, int wanted_sample_rate, struct AudioParams *audio_hw_params)
{
…
#ifdef _WIN32
CoInitialize(NULL);
#endif
while (!(audio_dev = SDL_OpenAudioDevice(NULL, 0, &wanted_spec, &spec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE | SDL_AUDIO_ALLOW_CHANNELS_CHANGE))) {
…
}
附件 (1)
ffplay_win32_call_coinitialize_before_opening_audio_device.patch (856 字节) - added by unknown 15个月 ago.
FFplay: win32: call CoInitialize? before opening audio device
Download all attachments as: .zip
Oldest first Newest first
Comments only
变更历史 (14)
comment:1 由 unknown 在 15个月 ago 前变更
关键词 添加了 sdl
版本 从 unspecified 改变为 3.4
Error message (in english language):
SDL_OpenAudio (1 channels, 48000 Hz): WASAPI can’t initialize audio client: CoInitialize has not been called.
comment:2 跟随: ↓ 3 由 cehoyos 在 15个月 ago 前变更
关键词 添加了 win; 删除了 ffplay windows win32 sdl sdl_openaudio wasapi coinitialize
Does it also fail with current FFmpeg?
comment:3 回复到: ↑ 2 由 unknown 在 15个月 ago 前变更
Replying to cehoyos:
Does it also fail with current FFmpeg?
Yes, this error happens also with current FFmpeg git (tested with zeranoe’s FFmpeg build ffmpeg-20171204-71421f3-win32-shared)
comment:4 由 cehoyos 在 15个月 ago 前变更
版本 从 3.4 改变为 git-master
由 unknown 在 15个月 ago 前变更
附件 ffplay_win32_call_coinitialize_before_opening_audio_device.patch added
FFplay: win32: call CoInitialize? before opening audio device
comment:5 由 cus 在 14个月 ago 前变更
抄送 添加了 cus
This seems like an issue which should be fixed in SDL instead of ffplay, no?
comment:6 由 mrchangkun 在 14个月 ago 前变更
any update?? ffmpeg-20180113-c51301d-win64-shared still error with wasapi cant initialize audio client.
comment:7 由 cehoyos 在 14个月 ago 前变更
Did you already report the issue to SDL?
comment:8 由 t.rapp 在 10个月 ago 前变更
Found something related which has been posted to SDL here:
https://discourse.libsdl.org/t/sdl-openaudio-wasapi-can-t-initialize-audio-client-coinitialize-has-not-been-called/23437
but seems like there is no response yet.
comment:9 由 t.rapp 在 10个月 ago 前变更
Another SDL post related to the issue:
https://discourse.libsdl.org/t/ffplay-not-work-with-sdl/23542
When looking up the implementation of WIN_CoInitialize() in SDL code some comment can be found:
If you need multi-threaded mode, call CoInitializeEx?() before SDL_Init()
So possibly this needs to be fixed on FFmpeg side by adding a call CoInitializeEx(NULL, COINIT_MULTITHREADED) at ffplay start-up. (Unfortunately my dev environment doesn’t contain SDL2 for cross-compilation to Windows so I cannot test this).
comment:10 由 Gyan 在 10个月 ago 前变更
Can you post a mbox patch against master? I can test it here. At present, I set a env variable before running ffplay.
comment:11 跟随: ↓ 12 由 CoRoNe 在 10个月 ago 前变更
Could this be an issue with SDL 2.0.7? SDL 2.0.8 was released on the 1st of march this year and has “Implemented WASAPI support on Windows UWP” in the changelog.
Zeranoe’s latest build (as well as mine) is built with SDL 2.0.8, so you could give it a try.
comment:12 回复到: ↑ 11 由 Gyan 在 10个月 ago 前变更
Replying to CoRoNe:
Could this be an issue with SDL 2.0.7? SDL 2.0.8 was released on the 1st of march this year and has “Implemented WASAPI support on Windows UWP” in the changelog.
Zeranoe’s latest build (as well as mine) is built with SDL 2.0.8, so you could give it a try.
No, same behaviour with Zeranoe’s build.
comment:13 由 cus 在 10个月 ago 前变更
Try to get some feedback from SDL about this. Also it would be good to know which fix should be used if any:
CoInitializeEx(NULL, COINIT_MULTITHREADED)
or simply
CoInitialize(NULL);
They seem to do different things…
标签:Hz,ago,enable,CoInitialize,OpenAudio,WASAPI,ffplay,SDL,audio 来源: https://blog.csdn.net/weixin_43674806/article/details/87914328