Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio broken on Ubuntu 18.04 LTS (installed via wheel) #71

Closed
ntoll opened this issue Jul 15, 2019 · 30 comments

Comments

@ntoll
Copy link

@ntoll ntoll commented Jul 15, 2019

Hi,

In a virtualenv with Python 3.7.3. I've followed the instructions for installing on Linux (i.e. https://kivy.org/doc/stable/installation/installation-linux.html#using-precompiled-wheels). I've checked the ffplay command works with the specific file (it does).

When I try to play audio I see the following in the logs:

[WARNING] [ffpyplayer  ] SDL_OpenAudio (2 channels, 44100 Hz): No such audio device
[WARNING] [ffpyplayer  ] SDL_OpenAudio (1 channels, 44100 Hz): No such audio device
[ERROR  ] [ffpyplayer  ] No more channel combinations to try, audio open failed
[CRITICAL] [ffpyplayer  ] Failed to open file '/home/ntoll/src/pyoa/meow1.wav' or configure filtergraph

Any idea what's going on..?

Thanks!

@ntoll

This comment has been minimized.

Copy link
Author

@ntoll ntoll commented Jul 15, 2019

BTW... with the latest daily for Python 3.7 (https://kivy.org/downloads/ci/linux/kivy/Kivy-2.0.0.dev0-cp37-cp37m-manylinux2010_x86_64.whl) I get the following new error messages:

[CRITICAL] [AudioSDL2   ] Unable to open mixer: b'No such audio device'
[WARNING] Deprecated property "<AliasProperty name=filename>" of object "<kivy.core.audio.audio_sdl2.SoundSDL2 object at 0x7fd728a768d0>" was accessed, it will be removed in a future version
[WARNING] [AudioSDL2   ] Unable to load /home/ntoll/src/pyoa/meow1.wav: b"Audio device hasn't been opened"
@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Jul 15, 2019

I'm not sure what is going on, but maybe the sdl2 version is too old or something for your system. You should try installing ffyplayer from source. It's really easy on 18.04.

@ntoll

This comment has been minimized.

Copy link
Author

@ntoll ntoll commented Jul 15, 2019

@matham sure... but the code I'm creating is a module that creates a shim around Kivy for some UI based capabilities aimed at beginner developers. Basically, I'd like to just say "pip install mypackage" (whatever I end up calling this) with kivy etc as dependencies. Compiling with Cython from source is not exactly a beginner friendly option for this module, IYSWIM.

Any suggestions would be welcome.

FWIW, the SDL2 version installed on my machine is, 2.0.8.dfsg1-1ubuntu1.18.04.3

@ntoll

This comment has been minimized.

Copy link
Author

@ntoll ntoll commented Jul 15, 2019

Hence the desire for binary wheels to "just work" on the current LTS version of Ubuntu. ;-)

@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Jul 16, 2019

I'm not really sure that I can suggest anything specific, other than trying to debug to see how ffpyplayer compiled from source different from the wheel (e.g. the sdl2 versions and if that fixes it).

The idea to be able to compile a wheel and have it work on all linux systems is somewhat of a tall order, especially since it's still quite experimental :) You can see the guts involved in getting this to work conceptually at https://discuss.python.org/t/the-next-manylinux-specification/1043. But specifically with hardware, it could be the wheel is missing some binary to make it work on your system, like sdl2 mixer. I cannot remember if it was compiled with support for it. The only way for me (or you :) ) to make sure is to test on multiple systems, figure out what is missing, and then update the wheels and a make a new release. I only tested on a couple of ubuntu systems. And unfortunately I don't really have the time to test more thoroughly.

@ntoll

This comment has been minimized.

Copy link
Author

@ntoll ntoll commented Jul 16, 2019

OK... so compiling on my local machine works. Thanks for the suggestion.

The problem I see is my little project is aimed at beginner level programmers and compiling ffpyplayer isn't exactly beginner-friendly. Having said that, I believe most of the users of the project will be on Windows or OSX (which I'll need to check once my project is "finished").

FWIW, I'm "reinventing" HyperCard in Python with Kivy as the UI layer. I've a bunch of beginner folks who want to create "visual" applications in Python that should work on both desktop and mobile.

Thanks for all your work on Kivy. Apart from the audio issue, everything has so far "just worked" ™️ ;-)

@okadath

This comment has been minimized.

Copy link

@okadath okadath commented Aug 13, 2019

I have the same problem in ubuntu 16.04 :

[CRITICAL] [AudioSDL2   ] Unable to open mixer: b'No such audio device'
[WARNING] Deprecated property "<AliasProperty name=filename>" of object "<kivy.core.audio.audio_sdl2.SoundSDL2 object at 0x7f92aca68db0>" was accessed, it will be removed in a future version
[WARNING] [AudioSDL2   ] Unable to load /home/oka/Desktop/kivy/simpleapp/bump.wav: b"Audio device hasn't been opened"
[WARNING] [AudioSDL2   ] Unable to load /home/oka/Desktop/kivy/simpleapp/bump.wav: b"Audio device hasn't been opened"
[WARNING] [AudioSDL2   ] Unable to load /home/oka/Desktop/kivy/simpleapp/bump.wav: b"Audio device hasn't been opened"
[WARNING] [AudioSDL2   ] Unable to load /home/oka/Desktop/kivy/simpleapp/bump.wav: b"Audio device hasn't been opened"
[WARNING] [AudioSDL2   ] Unable to load /home/oka/Desktop/kivy/simpleapp/game_over.wav: b"Audio device hasn't been opened"

if i generate the apk of the project the sound works perfectly in my cellphone

if I try to change the audio of the project they still don't sound anything:

os.environ['KIVY_AUDIO'] = 'avplayer'

i will try compile manually

@s0h3ck

This comment has been minimized.

Copy link

@s0h3ck s0h3ck commented Oct 31, 2019

Hello guys,

I had the same issue. An update of the pypi version might helps.

python3 -m pip install https://github.com/matham/ffpyplayer/archive/master.zip

Long story:

The following has been tested on ArchLinux and Debian.

  1. python3 -m pip install --upgrade --user pip setuptools virtualenv
  2. python3 -m virtualenv ~/kivy_venv
  3. source ~/kivy_venv/bin/activate
  4. python3 -m pip install kivy
  5. vim example.py
from kivy.core.audio import SoundLoader
​
sound = SoundLoader.load('mytest.wav')
if sound:
    print("Sound found at %s" % sound.source)
    print("Sound is %.3f seconds" % sound.length)
    sound.play()
  1. python example.py
[WARNING] [Config      ] Older configuration version detected (0 instead of 21)
[WARNING] [Config      ] Upgrading configuration in progress.
[INFO   ] [Logger      ] Record log in /root/.kivy/logs/kivy_19-10-30_0.txt
[INFO   ] [Kivy        ] v1.11.1
[INFO   ] [Kivy        ] Installed at "/root/kivy_venv/lib/python3.6/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.6.8 (default, Aug  7 2019, 17:28:10)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
[INFO   ] [Python      ] Interpreter at "/root/kivy_venv/bin/python3"
[INFO   ] [Audio       ] Providers: audio_sdl2 (audio_ffpyplayer ignored)
[CRITICAL] [AudioSDL2   ] Unable to open mixer: b'No such audio device'
[WARNING] Deprecated property "<AliasProperty name=filename>" of object "<kivy.core.audio.audio_sdl2.SoundSDL2 object at 0x7f1bd2f1cb40>" was accessed, it will be removed in a future version
[WARNING] [AudioSDL2   ] Unable to load mytest.wav: b'Mix_LoadWAV_RW with NULL src'
Sound found at mytest.wav
Sound is 0.000 seconds
  1. pip install ffpyplayer
  2. python example.py
[WARNING] [ffpyplayer  ] SDL_OpenAudio (2 channels, 44100 Hz): No such audio device
[WARNING] [ffpyplayer  ] SDL_OpenAudio (1 channels, 44100 Hz): No such audio device
[ERROR  ] [ffpyplayer  ] No more channel combinations to try, audio open failed
  1. python3 -m pip install https://github.com/matham/ffpyplayer/archive/master.zip
  2. python example.py
No sound :'(
  1. Let's try this example:
from kivy.core.audio import SoundLoader
import time

sound = SoundLoader.load('test.wav')
sound.seek(0)
sound.play()
time.sleep(1000)

sound.seek(0)
sound.play()
time.sleep(1000)

This example plays audio file only once.

  1. Let's try this example:
from kivy.core.audio import SoundLoader
from kivy.base import runTouchApp
from kivy.uix.button import Button
import time

sound = SoundLoader.load('a.wav')
sound.seek(0)

class MyLabel(Button):
    def on_release(self):
        sound.seek(0) # line I added 
        start_time = time.time()
        self.play_sound()
        print("--- %s seconds ---" % (time.time() - start_time))

    def play_sound(self):
        if sound:
            print("Sound found at %s" % sound.source)
            print("Sound is %.3f seconds" % sound.length)
            sound.play()

runTouchApp(MyLabel(text="Press me for a sound"))

This example plays the audio file every time I click on the button. I added sound.seek(0).

  1. Now, what if I want to play a different audio file. Here is a modified version that would allow you to select the audio files from a list, a database, and so on. It is a bit hacky. If anyone has a better example, please share it, thanks. 👍
from kivy.core.audio import SoundLoader
from kivy.base import runTouchApp
from kivy.uix.button import Button
import time
import random

class MyLabel(Button):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.sound = SoundLoader.load('a.wav') # hack to unload the sound...

    def on_release(self):
        self.sound.unload()

        audio_files = ['a.wav', 'b.wav']
        self.sound = SoundLoader.load(audio_files[random.randint(0,1)])
        self.sound.seek(0)
        start_time = time.time()

        if self.sound.state != 'play':
            self.play_sound()
        print("--- %s seconds ---" % (time.time() - start_time))

    def play_sound(self):
        if self.sound:
            print(self.sound.state)
            print("Sound found at %s" % self.sound.source)
            print("Sound is %.3f seconds" % self.sound.length)
            self.sound.play()

runTouchApp(MyLabel(text="Press me for a sound"))

If I do not unload the sound, I get the following error after 6 or 7 times clicking on the button. Here is the error:

[WARNING] [ffpyplayer  ] SDL_OpenAudio (2 channels, 44100 Hz): Too many open audio devices
[WARNING] [ffpyplayer  ] SDL_OpenAudio (1 channels, 44100 Hz): Too many open audio devices
[ERROR  ] [ffpyplayer  ] No more channel combinations to try, audio open failed
[CRITICAL] [ffpyplayer  ] Failed to open file '/root/kivy_venv/b.wav' or configure filtergraph

In conclusion, the last example of code works. I encourage anyone to improve the library because it is very time-consuming to be able to operate the sound correctly. Thanks!

@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Nov 6, 2019

I generated new wheels, and enabled more components for SDL2. Could you give the following wheel a try and let me know if it fixes the issue?
ffpyplayer-4.3.0.dev0-cp36-cp36m-manylinux2010_x86_64.zip

@s0h3ck

This comment has been minimized.

Copy link

@s0h3ck s0h3ck commented Nov 6, 2019

I have an issue with the version: ERROR: ffpyplayer-4.3.0.dev0-cp36-cp36m-manylinux2010_x86_64.whl is not a supported wheel on this platform. Do you have it for cp37? Thanks.

@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Nov 6, 2019

@s0h3ck

This comment has been minimized.

Copy link

@s0h3ck s0h3ck commented Nov 6, 2019

Ha ha thanks. I tried to search in the URL, but you have to decrease the number 3812631 to 3812630 in the URL. Nevermind! :)

The result is no, it doesn't work:

Sound found at /home/s0h3ck/a.wav
Sound is 1.747 seconds
--- 8.20159912109375e-05 seconds ---
[WARNING] [ffpyplayer  ] [wav @ 0x7f0b80000900] Discarding ID3 tags because more suitable tags were found.
[WARNING] [ffpyplayer  ] SDL_OpenAudio (2 channels, 44100 Hz): No such audio device
[WARNING] [ffpyplayer  ] SDL_OpenAudio (1 channels, 44100 Hz): No such audio device
[ERROR  ] [ffpyplayer  ] No more channel combinations to try, audio open failed
[CRITICAL] [ffpyplayer  ] Failed to open file '/home/s0h3ck/b.wav' or configure filtergraph

If you run pip install https://github.com/matham/ffpyplayer/archive/master.zip, it works.

@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Nov 6, 2019

Ok, here's a new version, with pulseaudio support: https://github.com/matham/ffpyplayer/suites/297818422/artifacts/254862. If that doesn't work, I'm not sure what else I can do.

@s0h3ck

This comment has been minimized.

Copy link

@s0h3ck s0h3ck commented Nov 6, 2019

It gives me a segment fault, but I see you modified the master again and the last tested commit "Add seemingly missing pkg-config." works. Let me know when you want me to test the new wheel version. Thanks.

@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Nov 6, 2019

It gives me a segment fault

The wheel or master?

None of the changes I made after I shared the wheels above are related to the linux wheels. So that should not fix anything regarding this issue. If the wheel I shared has a seg fault, then I probably shouldn't include pulseaudio and then I'm not sure how to fix this issue.

It probably is some incompatibility between some ubuntu audio library and the one on the centos 6 system used to build the wheels. But that is not something I can resolve it seems. It would need someone with the spare time to figure out the exact difference in sdl2 build flags etc between these two systems.

@s0h3ck

This comment has been minimized.

Copy link

@s0h3ck s0h3ck commented Nov 6, 2019

The packages here give me segment fault. And 30 minutes ago I did pip install https://github.com/matham/ffpyplayer/archive/master.zip, it gave me segment fault as well. And then you made a few changes... and I was trying to understand why with the master. The master works now.

Here is my testing workflow:

pip uninstall ffpyplayer
rm -rf ~/.cache/pip

pip install  https://github.com/matham/ffpyplayer/archive/master.zip
or
pip install git+https://github.com/matham/ffpyplayer.git@22a7299f97bb2a1766a6ffe58b3e2a200760ed84 (example)
@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Nov 6, 2019

Oh, I did change the cython language level from 2 to 3. But I don't think I fixed anything in master so I'm not sure why the set fault would have gone away.

I'll regenerate the wheels from master and share.

@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Nov 7, 2019

@s0h3ck

This comment has been minimized.

Copy link

@s0h3ck s0h3ck commented Nov 7, 2019

Yes. There is a segment fault in this one.

@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Nov 7, 2019

And it doesn't happen when you compile from master? When does the seg fault happen?

@s0h3ck

This comment has been minimized.

Copy link

@s0h3ck s0h3ck commented Nov 7, 2019

And it doesn't happen when you compile from master?

It works fine when I do:

pip install https://github.com/matham/ffpyplayer/archive/master.zip

When does the seg fault happen?

Good question. I added more verbose with the following command:

$ python -q -X faulthandler example.py

Fatal Python error: Segmentation fault

Thread 0x00007f406a7fc700 (most recent call first):

Current thread 0x00007f40aefb36c0 (most recent call first):
  File "/home/s0h3ck/.virtualenvs/test/lib/python3.7/site-packages/kivy/core/audio/audio_ffpyplayer.py", line 123 in load
  File "/home/s0h3ck/.virtualenvs/test/lib/python3.7/site-packages/kivy/core/audio/__init__.py", line 176 in on_source
  File "/home/s0h3ck/.virtualenvs/test/lib/python3.7/site-packages/kivy/core/audio/audio_ffpyplayer.py", line 98 in __init__
  File "/home/s0h3ck/.virtualenvs/test/lib/python3.7/site-packages/kivy/core/audio/__init__.py", line 86 in load
  File "example.py", line 17 in on_release
  File "/hom[WARNING] [ffpyplayer  ] [wav @ 0x7f4064000c80] Discarding ID3 tags because more suitable tags were found.
e/s0h3ck/.virtualenvs/test/lib/python3.7/site-packages/kivy/uix/behaviors/button.py", line 179 in on_touch_up
  File "/home/s0h3ck/.virtualenvs/test/lib/python3.7/site-packages/kivy/base.py", line 293 in post_dispatch_input
  File "/home/s0h3ck/.virtualenvs/test/lib/python3.7/site-packages/kivy/base.py", line 327 in dispatch_input
  File "/home/s0h3ck/.virtualenvs/test/lib/python3.7/site-packages/kivy/base.py", line 342 in idle
  File "/home/s0h3ck/.virtualenvs/test/lib/python3.7/site-packages/kivy/core/window/window_sdl2.py", line 479 in _mainloop
  File "/home/s0h3ck/.virtualenvs/test/lib/python3.7/site-packages/kivy/core/window/window_sdl2.py", line 747 in mainloop
  File "/home/s0h3ck/.virtualenvs/test/lib/python3.7/site-packages/kivy/base.py", line 504 in runTouchApp
  File "example.py", line 32 in <module>
Segmentation fault (core dumped)
@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Nov 8, 2019

Could you try testing this and/or the first wheel that didn't segfault by running with the env variable set to SDL_AUDIODRIVER=alsa or SDL_AUDIODRIVER=pulseaudio?

@s0h3ck

This comment has been minimized.

Copy link

@s0h3ck s0h3ck commented Nov 11, 2019

Test 1: SDL_AUDIODRIVER=alsa
Wheel: #71 (comment)
Result: Segmentation fault

Test 2: SDL_AUDIODRIVER=pulseaudio
Wheel: #71 (comment)
Result: Segmentation fault

Test 3: SDL_AUDIODRIVER=alsa
Wheel: pip install https://github.com/matham/ffpyplayer/archive/master.zip
Result: It works fine.

Test 4: SDL_AUDIODRIVER=pulseaudio
Wheel: pip install https://github.com/matham/ffpyplayer/archive/master.zip
Result: It works fine.

@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Nov 11, 2019

OK, thanks for testing. At this point I'm not really sure what I could do. I'll probably make a new release so I could upload the new windows wheels, but I guess the Linux wheels just won't support audio for now.

@s0h3ck

This comment has been minimized.

Copy link

@s0h3ck s0h3ck commented Nov 11, 2019

Can you do the wheel again? It is a bit weird that it works from the master, but not from the wheel.

Edit: I cloned the repository and generated the packages (linux and .tar) and it works fine. Can you show me how you do the wheels packaging?

@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Nov 11, 2019

You could try the latest master wheel again https://github.com/matham/ffpyplayer/suites/303119116/artifacts/281238, but the difference is not with master vs the wheel, it's the difference in binary dependencies.

When you compile with master, ffpyplayer links with and uses ubuntu's sdl2 etc from your system. But for the wheels, we build these deps on centos and distribute them in the wheel.

So obviously something is wrong with the deps used by sdl2 that are included in the wheel and that doesn't work on Ubuntu. But it's not clear what exactly the issue is. I thought adding pulse audio support would fix it, but that made it segfault.

@s0h3ck

This comment has been minimized.

Copy link

@s0h3ck s0h3ck commented Nov 13, 2019

I understand. I tested again and I still have a segfault. Curiosity, if I do pip install ffpyplayer-4.3.0.dev0.tar.gz should it work? I am not an expert, but what are the reasons why I have Cython errors like this:

  Error compiling Cython file:
  ------------------------------------------------------------
  ...
      >>> img2 = copy.deepcopy(img)
  '''
  
  __all__ = ('Image', 'SWScale', 'get_image_size', 'ImageLoader')
  
  include "includes/inline_funcs.pxi"
  ^
  ------------------------------------------------------------
@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Nov 14, 2019

So I think I finally tracked down the issue and a workaround. Here are the new wheels https://github.com/matham/ffpyplayer/suites/309864390/artifacts/316423.

So after reproducing locally, which made testing much easier, I saw that sdl2 mixer is somehow not working. I'm not sure why, but likely some binary incompatibility. Specifically, that blocks certain threads and causes the other issues.

The fix is to not use sdl2 mixer for the manylinux wheels, but rather sdl2 directly. This disables the ability to play multiple audio source at the same time. If that is needed, you'd still need to compile locally on your machine. Unless someone is willing to figure out what exactly the issue is with sdl2 mixer compiled on the CI.

But these new wheels should just work (hopefully). If you can confirm it works, I'll make a new release and upload to pypi.

pip install ffpyplayer-4.3.0.dev0.tar.gz

Not sure, where are you getting this file from? Because old releases had this issue I think, but it shouldn't be with master.

@s0h3ck

This comment has been minimized.

Copy link

@s0h3ck s0h3ck commented Nov 14, 2019

I tested the new wheel and it looks like it works! I got no segment fault. Thanks! :)

Not sure, where are you getting this file from? Because old releases had this issue I think, but it shouldn't be with master.

I get it from your wheel:

ffpyplayer-4.3.0.dev0-cp35-cp35m-manylinux2010_x86_64.whl
ffpyplayer-4.3.0.dev0-cp36-cp36m-macosx_10_9_x86_64.macosx_10_9_intel.macosx_10_10_intel.macosx_10_10_x86_64.whl
ffpyplayer-4.3.0.dev0-cp36-cp36m-manylinux2010_x86_64.whl
ffpyplayer-4.3.0.dev0-cp36-cp36m-win32.whl
ffpyplayer-4.3.0.dev0-cp36-cp36m-win_amd64.whl
ffpyplayer-4.3.0.dev0-cp37-cp37m-macosx_10_9_x86_64.macosx_10_9_intel.macosx_10_10_intel.macosx_10_10_x86_64.whl
ffpyplayer-4.3.0.dev0-cp37-cp37m-manylinux2010_x86_64.whl
ffpyplayer-4.3.0.dev0-cp37-cp37m-win32.whl
ffpyplayer-4.3.0.dev0-cp37-cp37m-win_amd64.whl
ffpyplayer-4.3.0.dev0-cp38-cp38-macosx_10_9_x86_64.macosx_10_9_intel.macosx_10_10_intel.macosx_10_10_x86_64.whl
ffpyplayer-4.3.0.dev0-cp38-cp38-manylinux2010_x86_64.whl
ffpyplayer-4.3.0.dev0-cp38-cp38-win32.whl
ffpyplayer-4.3.0.dev0-cp38-cp38-win_amd64.whl
ffpyplayer-4.3.0.dev0.tar.gz
@matham

This comment has been minimized.

Copy link
Owner

@matham matham commented Nov 14, 2019

Oh, hmm. I'll give the zip a try, because that should work fine (but I hadn't tested it).

Thanks for all your help testing. I guess I'll close this now.

@matham matham closed this Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.