Installing ffmpeg from dmg and then running from a terminal, is there a better way?

From here: https://ffmpeg.org/download.html#build-mac I chose static builds 64-bit which too me to https://evermeet.cx/ffmpeg/

I then downloaded this:

enter image description here

and opened it using this:

enter image description here

which gave me this:

Last login: Wed Jun  6 09:41:56 on ttys000
david-selfs-Air:~ david$ /Volumes/FFmpeg\ 91200-g1616b1be5a/ffmpeg ; exit;
ffmpeg version N-91200-g1616b1be5a-tessus Copyright (c) 2000-2018 the FFmpeg developers
  built with Apple LLVM version 9.1.0 (clang-902.0.39.1)
  configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
  libavutil      56. 18.102 / 56. 18.102
  libavcodec     58. 19.104 / 58. 19.104
  libavformat    58. 17.100 / 58. 17.100
  libavdevice    58.  4.100 / 58.  4.100
  libavfilter     7. 24.100 /  7. 24.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Deleting expired sessions...7 completed.

[Process completed]

However when I open a terminal and try ffmpeg or man ffmpeg or even ffmpeg -i filename.mp4 -vn filename.wav(from here) all I get is

-bash: ffmpeg: command not found

I must be close, is there a place where I now need to define a path for ffmpeg? I don't know how to do that, or what path to use.

Is there a better way?


Solution 1:

The problem is bash is looking for ffmpeg in directories list in the $PATH. Some of these directories are protected by SIP and therefore you would need to disable SIP to put the file in these directories. Alternatively, you can install it using Homebrew.

First install HomeBrew with this command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then install ffmpeg with this command:

brew install ffmpeg

Homebrew will install ffmpeg in a path not protected by SIP, but within the $PATH, more specifically it will install it under the /usr/local/bin directory.

This can be done manually with manual commands (basically manually doing what homebrew does. For this approach check out @davids answer. But I would suggest homebrew for multiple reasons. Its much easier to use and quicker to install a large amount of tools. You can also update much faster. Homebrew also makes installing dependencies easier.

Edit: I previously had a part of this answer with inaccurate information I have since changed it. I believe it is currently accurate. I have included the part about SIP because I think it is important to understand what restrictions there are regarding placement of commands and why there isn't just a single path for all commands.

Solution 2:

You are supposed to copy the program from the disk image to your local folders. The usual place for these things is /usr/local/bin

So:

sudo mkdir -p /usr/local/bin
sudo cp /Volumes/FFmpeg\ 91200-g1616b1be5a/ffmpeg /usr/local/bin/
sudo chmod +x /usr/local/bin/ffmpeg

and all should be good to go. Disabling SIP not required.

No need for homebrew or any other package handler to install a precompiled binary. You do need to read up on basic UNIX though.

Solution 3:

The terminal shell of macOS, as in Windows or Linux, is looking in the $PATH environment variable to locate binaries.

You can check your $PATH variable doing :

echo $PATH

Which outputs in standard recent macOS :

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

You either have to put a copy of the binary in one of those directory (preferably /usr/local/bin as it is not SIP-protected) or add another directory in your $PATH environment variable.

The best practice is generally to store your application elsewhere (e.g. /lib) and to only put a symlink in the bin directory pointing to the binary itself. This is less true for self-contained binary but mandatory if you want to run an executable that resides inside an .app (e.g. /Applications/VLC.app/Contents/MacOS/VLC)