marzzzello / mpv_thumbnail_script

A Lua script to show preview thumbnails in mpv's OSC seekbar, sans external dependencies (fork)
GNU General Public License v3.0
276 stars 20 forks source link

Failure to locate mpv binary on macOS/Homebrew MPV installation (with workaround) #29

Open rucker opened 2 years ago

rucker commented 2 years ago

Description of the bug Thumbnailer job will fail to invoke mpv on macOS which causes the entire job to fail. Relevant log output is:

[   2.100][e][mpv_thumbnail_script_server] Thumbnailing command failed!
[   2.100][e][mpv_thumbnail_script_server] mpv process error: init
[   2.100][e][mpv_thumbnail_script_server] Process stdout:
[   2.100][e][mpv_thumbnail_script_server] Debug log: /tmp/mpv_thumbs_cache/test-file/000000.bgra.log
[   2.101][e][mpv_thumbnail_script_server] Output file missing! /tmp/mpv_thumbs_cache/test-file/000000.bgra

To Reproduce Steps to reproduce the behavior:

Expected behavior Thumbnailing job completes normally

Environment

The Workaround I noticed that the issue did not occur when I ran mpv on the CLI. Through some testing according to #16, I verified that the issue is that the mpv_command built by the script fails to invoke mpv. I worked around this by modifying the relevant line in the server to use the absolute path to mpv and everything works as expected. Either the homebrew bin path (which is a symlink to the application bundle, below) or the path to the binary in the app bundle worked just fine.

$ ls -l `which mpv`
lrwxr-xr-x 1 me admin 40 Oct  9 13:04 /opt/homebrew/bin/mpv -> /Applications/mpv.app/Contents/MacOS/mpv

As shown above, the Homebrew path /opt/homebrew/bin is on my user's $PATH. Adding the appropriate path to /etc/paths before starting MPV had no effect.

Recommendations From a look through the code, it seems as though the server ExecutableFinder, which loads the user's environment to search for ffmpeg, could be used to find mpv as well.

marzzzello commented 1 year ago

How did you modify the PATH variable? It looks like the CLI uses a different environment than the UI. https://www.bounga.org/tips/2020/04/07/instructs-mac-os-gui-apps-about-path-environment-variable/ Have you tried setting the PATH in /etc/launchd? EDIT: In the comments someone says that it no longer works :/

rucker commented 1 year ago

I am setting my PATH in my .bashrc. From what I've read, exposing user env vars to GUI applications on macOS is a nontrivial problem with a lot of potential solutions (depending on the version -- as you mentioned, launchd used to be one possibility but this is no longer the case).

At any rate, unless you want this thumbnailer script to go looking in known locations like Homebrew's bin dir that aren't on the default PATH (I understand if you don't), it seems to me that this is more of a system configuration issue.

Here are some possible solutions for anyone else facing this situation:

  1. Hard-code the path to mpv as shown in the OP above.
  2. Various possibilities listed here (warning, this is an old question with old answers so YMMV).

Unless there are other possibilities I'm not thinking of, you can probably close this issue.

marzzzello commented 1 year ago

So none of the possibilities in [2.] work? launchctl setenv PATH $PATH looked promising. I could also add an option for setting the path to mpv.

SemperPeritus commented 1 year ago

The same problem. My workaround here: https://github.com/TheAMM/mpv_thumbnail_script/issues/61

rucker commented 1 year ago

So none of the possibilities in [2.] work? launchctl setenv PATH $PATH looked promising. I could also add an option for setting the path to mpv.

I haven't tried everything in that SO thread, but launchctl setenv PATH $PATH unfortunately did not do the trick. I verified that the path is correct via launchctl getenv PATH but it had no apparent effect -- launching MPV after setting this resulted in the thumbnailer job failing as before. I agree it looked promising though!

rucker commented 1 year ago

@marzzzello @SemperPeritus Please have a look at #39, which I think will resolve this.