jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
543 stars 68 forks source link

mac error on launching example #148

Open jdauthre opened 3 years ago

jdauthre commented 3 years ago

I am using mojave on my mac and have installed libmpv via homebrew and python-mpv via pip3. on launching a simple example via idle: import mpv player = mpv.MPV(ytdl=True) player.play('/Documents/NHK.mp4') player.wait_for_playback()

I get an error: Traceback (most recent call last): File "/Users/jdauthre/Documents/python/mpvmini.py", line 1, in import mpv File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/mpv.py", line 52, in backend = CDLL(sofile) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/init.py", line 373, in init self._handle = _dlopen(self.name, mode) OSError: dlopen(/usr/local/lib/libmpv.dylib, 6): Symbol not found: $sSo13NSWindowLevela6AppKit01_cdD23NumericRawRepresentableACMc Referenced from: /usr/local/lib/libmpv.dylib Expected in: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftAppKit.dylib in /usr/local/lib/libmpv.dylib

What do I need to do to get it to run? Thanks in advance

jdauthre commented 3 years ago

Anyone?

jaseg commented 3 years ago

I'm not a mac user, but this error would could be explained by the system libraries being updated. A libmpv version compiled and linked for an older library version might not work with a newer version.

If I am guessing right, you can fix this by updating/recompiling your libmpv using homebrew. From a quick search it looks like brew reinstall --build-from-source should do the trick.

jdauthre commented 3 years ago

thanks I will try this

jdauthre commented 3 years ago

Unfortunately it didn't work, so I moved on to trying it on Catalina. It works fine on that. However if I may another issue has appeared. I have a wx.slider in the script which acts as a progess bar and as a seek so you can move quickly though the video to find the place you want. All works well on windows, but on the mac you can go maybe 100 secs and it freezes, how far it gets is variable depending on how quickly I move the slider and other unknown variables. I am assuming as the basic coding is presumably correct that it is a speed/buffer issue? but I can't find which buffer to focus on and how to increase the size. Any ideas?

jaseg commented 3 years ago

You could try running your script inside gdb or lldb, as in gdb --args python3 your_script.py [script args]

Then, after it freezes you can press Ctrl+C on the terminal to interrupt GDB and print a backtrace with the "bt" command. That backtrace might show you the function where libmpv is hanging.

As a general note, in case you currently fire one mpv property set action every time wxwidgets calls an event handler, it might make sense to have some rate limiting in that. I don't know much wx, but in Qt there are timers you can use for this: The basic idea would be to have a timeout of say, 100ms after every change in value during which new changes are ignored. This might be enough to prevent python-mpv/mpv from getting tangled up.

jdauthre commented 3 years ago

Thanks! I tried gdb but kept getting a 'gdb mac warning: unhandled dyld version (16)' which on googling looked as if I would spend more time debugging the debugger than the application! However I did manage to narrow down the issue to the seek() function on the core module. wx does have a timer, but the wx.slider doesn't have an 'on press' handler, and after some experimenting I got it to work by using the wx.timer, disabling the event handler for the slider, seeking to the new position, and using a wx.thumbup handler to stop the timer and renable the first handler. So all is good

btw python-mpv is great thanks, I was looking for an alternative to Gstreamer which I found to be very buggy.