MacOS no audio when playing videos
tbennett6421 opened this issue · 8 comments
Hydrus version
481
Operating system
macOS 11 "Big Sur" (Apple silicon)
Install method
Installer
Install and OS comments
install via disk image (dmg)
Bug description and reproduction
no audio when playing videos in hydrus. Has not worked since install. There is no audio output on either the preview player or the full player
Log output
No response
This isn't a bug with hydrus, but a bug with how the mpv library works with Qt on macOS. jaseg/python-mpv#61
Normally, hydrus video playback uses mpv, but on macOS, mpv can't work, so it's disabled, and some legacy player code that doesn't have audio support runs instead.
Is there no workaround to install/load mpv via homebrew or an alternative player?
It doesn't matter how you install mpv, it won't work because of the linked issue. To resolve this issue, someone needs to implement a workaround somewhere, so it's gonna require some programming. Unfortunately, I tried to take a crack at it a while ago, but I have absolutely zero experience with Qt and macOS GUI programming so I got nowhere. The owner of this project knows about this limitation and that's why the macOS build disables mpv, but I think he is also in no place to go fix the underlying bug in the third party libs. So we're probably screwed unless someone who does know what they're doing takes interest in fixing it, or one of us teaches himself enough to fix the bug on his own, lmao
same issue in ubuntu OS here.
@HerveKuate I am 99% sure it should work on Linux if you have mpv installed, and if you are having issues even if mpv is installed, it would be a separate issue than the fundamental problem on macOS, so you'd want to either get help on the discord about it or open a new github issue.
I asked help on discord, thanks for the advice.
@roachcord3 thank you for this information about python-mpv on macOS. What a shame. I had spent a bunch of time trying to get mpv built into the macOS App, having mixed success and knowing there was a 100% CPU problem still to solve, and it seems like that second problem is more serious. There are some interesting ideas in that python-mpv thread on how to get around this with subprocess, so I've recorded that stuff for now and will think about it when I revisit this topic.
I am going to close this issue for now. Hope to have proper mpv support on macOS in future, but for now it just seems a no-go.
Ok, this is super janky, because not only does it seem to produce a not-completely-functioning player, but it also causes exceptions to get thrown, BUT I did manage to use some reimplementation of just a part of the python-mpv
library called python-mpv-jsonipc
(was mentioned in the original issue as working on macOS, because it's implemented in a way that lets it communicate with external instances of mpv) and I actually got a video to start playing with audio and all that. It launched an external window, which I'm not sure is the intended experience, but it did work without pressing the shortcut to open in an external program.
Since hydrus is using part of the python-mpv API that wasn't reimplemented, I had to shove it back in. Here's the code diff:
diff --git a/hydrus/client/gui/canvas/ClientGUIMPV.py b/hydrus/client/gui/canvas/ClientGUIMPV.py
index 5b659487..fd707c62 100644
--- a/hydrus/client/gui/canvas/ClientGUIMPV.py
+++ b/hydrus/client/gui/canvas/ClientGUIMPV.py
@@ -21,8 +21,9 @@ from hydrus.client.gui import QtPorting as QP
mpv_failed_reason = 'MPV seems ok!'
try:
-
- import mpv
+ from mpv import MpvEventID
+ import python_mpv_jsonipc as mpv
+ mpv.MpvEventID = MpvEventID
MPV_IS_AVAILABLE = True
I was even able to seek with arrow keys! So some of the messaging actually works. I didn't bother trying every little thing because of how janky it is, I just wanted to share.
Of course, it causes a bunch of exceptions, such as BrokenPipeErrors
when trying to send some keyboard commands (this error seems to be about pausing, but, I was actually able to pause and resume just fine):
v499, 2022/09/15 19:32:20: Uncaught exception:
v499, 2022/09/15 19:32:20: BrokenPipeError
[Errno 32] Broken pipe
File "/Users/me/hydrus/src/hydrus/client/gui/ClientGUIShortcuts.py", line 1339, in eventFilter
shortcut_processed = self._ProcessShortcut( shortcut )
File "/Users/me/hydrus/src/hydrus/client/gui/ClientGUIShortcuts.py", line 1202, in _ProcessShortcut
command_processed = self._parent.ProcessApplicationCommand( command )
File "/Users/me/hydrus/src/hydrus/client/gui/canvas/ClientGUIMPV.py", line 383, in ProcessApplicationCommand
self.PausePlay()
File "/Users/me/hydrus/src/hydrus/client/gui/canvas/ClientGUIMPV.py", line 361, in PausePlay
self._player.pause = not self._player.pause
File "/Users/me/.pyenv/versions/hydrus-venv/lib/python3.9/site-packages/python_mpv_jsonipc.py", line 628, in __getattr__
return self.command("get_property", name.replace("_", "-"))
File "/Users/me/.pyenv/versions/hydrus-venv/lib/python3.9/site-packages/python_mpv_jsonipc.py", line 624, in command
return self.mpv_inter.command(command, *args)
File "/Users/me/.pyenv/versions/hydrus-venv/lib/python3.9/site-packages/python_mpv_jsonipc.py", line 323, in command
self.socket.send({"command":command_list, "request_id": command_id})
File "/Users/me/.pyenv/versions/hydrus-venv/lib/python3.9/site-packages/python_mpv_jsonipc.py", line 161, in send
self.socket.send(json.dumps(data).encode('utf-8') + b'\n')
As well as a TypeError that occurred at some point when I was trying to interact with the media window underneath the external mpv player window:
v499, 2022/09/15 19:32:38: Uncaught exception:
v499, 2022/09/15 19:32:38: TypeError
'>' not supported between instances of 'int' and 'PySide2.QtWidgets.QWidget'
File "/Users/me/.pyenv/versions/hydrus-venv/lib/python3.9/site-packages/python_mpv_jsonipc.py", line 612, in terminate
self.event_handler.stop(join)
File "/Users/me/.pyenv/versions/hydrus-venv/lib/python3.9/site-packages/python_mpv_jsonipc.py", line 361, in stop
self.join(join)
File "/Users/me/.pyenv/versions/3.9.13/lib/python3.9/threading.py", line 1064, in join
self._wait_for_tstate_lock(timeout=max(timeout, 0))
And it seems like the media window has no idea what's going on with the mpv window. I'm like 20 seconds into the actual video at this point, but the media window still thinks I'm on frame 1:
But, yeah, this is somewhat exciting. I wonder if it's possible to make the macOS build use this JSON IPC version instead, and have it handle events slightly differently specifically when using that version. If nothing else, this probably will help me and maybe a few others come closer to making python-mpv work on macOS.