mpv_thumbnail_script
mpv_thumbnail_script copied to clipboard
Failure to locate mpv binary on macOS/Homebrew MPV installation (with workaround)
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:
- On macOS, install MPV via Homebrew
- Add Homebrew
bin
dir to$PATH
- Set up thumbnail scripts and launch a video with
autogenerate=true
in your conf file. - Observe the error "Thumbnailing failed, check console for errors" in MPV
- Check log file for output
Expected behavior Thumbnailing job completes normally
Environment
- OS: macOS Monterey 12.6
- mpv version: 0.34.1
- mpv_thumbnail_script version: 0.4.9
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.
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 :/
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:
- Hard-code the path to
mpv
as shown in the OP above. - 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.
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.
The same problem. My workaround here: https://github.com/TheAMM/mpv_thumbnail_script/issues/61
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!
@marzzzello @SemperPeritus Please have a look at #39, which I think will resolve this.