ekisu / mpv-webm

Simple WebM maker for mpv, with no external dependencies.
MIT License
555 stars 32 forks source link

sh: mpv: command not found #135

Open frozenpandaman opened 2 years ago

frozenpandaman commented 2 years ago

mpv version and platform

macOS 12.0.1

$ mpv --version                                                  
mpv 0.33.1 Copyright © 2000-2020 mpv/MPlayer/mplayer2 projects
 built on Tue Nov  2 06:21:53 UTC 2021
FFmpeg library versions:
   libavutil       56.70.100
   libavcodec      58.134.100
   libavformat     58.76.100
   libswscale      5.9.100
   libavfilter     7.110.100
   libswresample   3.9.100
FFmpeg version: 4.4.1

mpv was installed via brew install mpv.

Description

Installing this fresh on a new machine, all encodes are failing because for some reason the script cant find mpv, even though its installed on the command line. The proper Command line: mpv ... & run_subprocess_popen: running mpv ... commands are triggering and successfully being logged, and manually copy-pasting that command into a new Terminal session works, but Im getting the following right after it when its being run via the script in mpv:

[v][webm] "sh: mpv: command not found" 

But if I launch sh (/bin/sh) it knows what the mpv command is, which I installed via Homebrew (cask version). To note, /bin is indeed on my PATH.

Hopefully Im just overlooking something simple here! Thanks.

frozenpandaman commented 2 years ago

manually copy-pasting that command into a new Terminal session works

Ive discovered this the above is true when the output format is set to webm, though if converting to mp4 (h264/AAC) I get:

[encode] codec 'libx264' not found.
 (+) Video --vid=1 (*) (h264 320x240 15.000fps)
 (+) Audio --aid=1 (*) (aac 6ch 48000Hz)
[encode] codec 'libx264' not found.
Error opening/initializing the selected video_out (--vo) device.
Video: no video

[encode] no data written to target file

But I do have it installed:

$ x264 --version                                                 
x264 0.163.3060 5db6aa6
built on Oct 22 2021, clang: 13.0.0 (clang-1300.0.29.3)
x264 configuration: --chroma-format=all
libx264 configuration: --chroma-format=all
x264 license: GPL version 2 or later

And for reference:

$ mpv --vo=help                                                  
Available video outputs:
  libmpv           render API for libmpv
  gpu              Shader-based GPU Renderer
  null             Null video output
  image            Write video frames to image files
  tct              true-color terminals
ekisu commented 2 years ago

Does setting display_progress = false on the options work? When using display_progress we use Lua's io.popen function, it might have some different interactions with how macOS/Homebrew works.

As for the libx264 codec, it probably has something with the ffmpeg library linked with this mpv build. Running mpv --ovc=help should list the supported codecs

frozenpandaman commented 2 years ago

Does setting display_progress = false on the options work?

Nope, tried putting this in script-opts/webm.conf and still says encode failed with the log message sh: mpv: command not found. I tried changing default shells, etc. and it doesnt seem to affect this – for some reason from within mpv.app it doesnt know where the mpv binary is or what that command is. If theres a way to make it use ffmpeg instead, I could maybe try that (and see if it also cant find that command – but as this scripts not supposed to have external dependencies I guess thats not ideal either).

Running mpv --ovc=help should list the supported codecs

libx264 is indeed in that list:

Available output video codecs:
  [...]
  --ovc=libx264      libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
  [...]

Full output here if youre interested. But I guess this is a secondary issue (as this is only when I paste one command into Terminal manually)… not even getting this within mpvs log file yet or anything, its always still "mpv: command not found".

Also note this is a fresh install of mpv + the script on a new computer, so Im not sure what could be messing up!?

frozenpandaman commented 2 years ago

I tried changing default shells, etc. and it doesnt seem to affect this

Turns out I was wrong about this and didnt test it correctly! Tried making /bin/sh my default shell, and I get:

-sh: mpv: command not found

I think this could be an M1 Mac/ARM64 problem – because Homebrew installs into /usr/local on Intel Macs (and /usr/local/bin is in the default sh PATH) but into /opt/homebrew on Apple Silicon (which is not on my PATH), i.e. mpv gets installed by brew into somewhere that is default to the sh path on some architectures, and not others.

I can manually add Homebrew to my sh PATH by adding export PATH="$PATH:/opt/homebrew/bin" to ~/.profile – but I think a better solution would be to modify the scripts run_subprocess() function to use whatever your default shell is, not sh.

EDIT: Nope, nevermind. Reading the mpv docs, it says about the utils.subprocess env argument: "Set a list of environment variables for the new process (default: empty). If an empty list is passed, the environment of the mpv process is used instead." So my shell should be being used, not sh. And utils.run (which utils.subprocess is an extension of) "doesnt call the shell" – and theyre right, adding the export line in ~/.profile fixes it when I manually run the command from a new Terminal instance, but the script is still broken and Im still getting sh: mpv: command not found.

EDIT 2: OK, last update/discovery for now. Everything works fine when I run mpv via the command line and then use the GUI there to trim/crop/convert/etc. a video (which makes sense – its inheriting the environment of my shell). Its only when launching mpv via the .app bundle that it produces this error. See this issue in the homebrew-cask repo discussing the state of the cask vs. the formula. Im also using an .app I built myself, using steps I described here (but its just the installed-by-brew mpv binary packaged up). But also to note, this issue is present even when using the "official" cask provided by Homebrew.

TL;DR

Its an M1 Mac issue. On Intel devices, Homebrew installs stuff (like mpv) in /usr/local/bin, which is on the default sh PATH, which gets loaded when launching the cask/.app version of mpv – rather than running it from the command line where it inherits your shells PATH. But on Apple Silicon devices (ARM64 architecture), Homebrew stuff gets put in /opt/homebrew/bin instead.

A workaround for now is just to symlink the mpv binary into /usr/local/bin.