70

Is there a good place or bash script I can use (or at least a version I can build myself) for FFmpeg on OS X?

I have Xcode installed as well as the CLI for Xcode (gcc etc).

I have a version of FFmpeg currently installed, but somehow I get a segmentation error on libx264 as well as the libvpx (I can't convert to MP4 and WebM).

All I want to do is batch convert video files to HTML5 compatible videos. All my source videos consist of .mov .mp4 and .wmv files. .ogv works fine by the way.

So the real question:

  1. How to uninstall everything of FFmpeg on my Mac now
  2. Reinstall a FFmpeg version that can convert to .mp4, .webm, and .ogv

I also tried the precompiled version of Miro video converter but somehow that doesn't work either.

0

3 Answers 3

111

There are four options, sorted by complexity:

  • Homebrew (or other package managers)
  • Static builds
  • Docker
  • Compile yourself

To follow this you need to have a bit of knowledge using a terminal/shell under macOS.


1. Homebrew

Homebrew has a formula for stable FFmpeg releases. This will get you running pretty fast. First, install Homebrew.

Then install FFmpeg through the ffmpeg formula:

brew install ffmpeg

This will download a lot of dependencies such as x264, but after that you should be good to go.

To update ffmpeg later on, run:

brew update && brew upgrade ffmpeg

2. Static Builds

The FFmpeg project, on the download page, offers links to static builds for ffmpeg, which you can just download, extract, and use in a terminal.

Static builds cannot contain every possible encoder, mostly due to licensing issues. This is why I don't recommend using them unless you don't really care about which specific features you need.

Once downloaded, extract the file, open up Terminal.app, and navigate to the directory where you unzipped the files, i.e. where you find a file called ffmpeg. Copy this file to /usr/local/bin:

cd ~/Downloads/
sudo mkdir -p /usr/local/bin/
sudo cp ./ffmpeg /usr/local/bin
sudo chmod ugo+x /usr/local/bin/ffmpeg

Now, if you use Bash (which is the default shell), add it to your $PATH:

open -e ~/.bash_profile

Add this to the file at the end:

export PATH="/usr/local/bin:$PATH"

Save it, and close the editor. Now restart your Terminal and which ffmpeg should return /usr/local/bin/ffmpeg.


3. Docker

If you have Docker installed you can run a Docker container that comes with ffmpeg preinstalled.

There are various ffmpeg Docker images out there, for instance linuxserver/ffmpeg (see other answer below).

To run this image to convert an input.mkv file into an output file, open a Terminal and run:

docker run --rm -it \
  -v $(pwd):/config \
  linuxserver/ffmpeg \
  -i /config/input.mkv \
  -c:v libx264 \
  -b:v 4M \
  -vf scale=1280:720 \
  -c:a copy \
  /config/output.mkv

Note that $(pwd) will be your current working directory, and the command expects that directory to contain the referenced input file input.mkv. The file will be mounted into the container (into the /config directory).


4. Compiling yourself

You can of course build FFmpeg tools yourself, following the OS X compilation guide. This guide will always be up to date, and by manually compiling you may be able to tweak a few parameters.


To uninstall whatever version of FFmpeg you installed we'd need to know how you've installed it in the first place. Since Homebrew will install to /usr/local/Cellar, and symlink to /usr/local/bin/ffmpeg, it probably won't cause any problems with other libraries. However, check the make install scripts of the versions you (supposedly) built yourself and see where they placed FFmpeg. Then just delete them from there — it won't interfere with Homebrew.

The segmentation fault could be due to improper linking between the x264 or libvpx libraries. Since Homebrew will take care of this, you shouldn't run into any issues.

6
  • For ffprobe via static builds it works the same way.
    – Marc_Alx
    Jan 29, 2021 at 16:20
  • ffmpeg is also available via MacPorts: sudo port selfupdate && sudo port install ffmpeg
    – Lorrin
    Mar 3, 2022 at 1:00
  • 1
    @Lorrin Thanks for the info. I am aware of this, but the MacPorts version is not always up to date. Right now it is 4 months behind.
    – slhck
    Mar 3, 2022 at 10:47
  • 1
    You weren't kidding about all those dependencies! Took 13 minutes to run brew install ffmpeg!!
    – turnip
    Aug 4, 2022 at 10:50
  • 1
    @GregoryCosmoHaun Thanks. I added Docker as an alternative in my answer as well. (There used to be another image that is not up to date anymore: hub.docker.com/r/jrottenberg/ffmpeg — so I was refraining from recommending that.)
    – slhck
    Jul 21, 2023 at 9:20
4

Install FFmpeg on the new ARM silicon (M1 chip): Install Rosetta2 via terminal using:

/usr/sbin/softwareupdate --install-rosetta --agree-to-license

Once Rosetta2 installed we can install Homebrew for ARM M1 chip:

arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

Once the installation is finished, use the next Homebrew command to install ffmpeg: arch -x86_64 brew install ffmpeg

1
  • 1
    Thanks, very helpful with Apple Silicon!
    – Qiao Zhang
    Oct 24, 2022 at 3:17
3

Instead of homebrew, I recommend using ffmpeg via docker:

docker run --rm -it \
  -v $(pwd):/config \
  linuxserver/ffmpeg \
  -i /config/input.mkv \
  -c:v libx264 \
  -b:v 4M \
  -vf scale=1280:720 \
  -c:a copy \
  /config/output.mkv

This docker image come from: https://hub.docker.com/r/linuxserver/ffmpeg


Last time I install ffmpeg by homebrew, I got this output:

> brew install ffmpeg
==> Fetching dependencies for ffmpeg: giflib, highway, imath, jpeg-turbo,
libpng, openexr, xz, libtiff, webp, jpeg-xl, libvmaf, aom, dav1d, freetype,
fontconfig, frei0r, gmp, bdw-gc, libtool, libunistring, guile, libidn2,
libtasn1, nettle, p11-kit, unbound, gnutls, lame, fribidi, pcre2, glib,
xorgproto, libxau, libxdmcp, libxcb, libx11, libxext, libxrender, lzo,
pixman, cairo, graphite2, harfbuzz, libunibreak, libass, libbluray,
cjson, cmocka, mbedtls, librist, libsoxr, libvidstab, libogg, libvorbis,
libvpx, opencore-amr, little-cms2, openjpeg, opus, rav1e, flac, mpg123,
libsndfile, libsamplerate, rubberband, sdl2, snappy, speex, srt, leptonica,
libb2, libarchive, pango, tesseract, theora, x264, x265, xvid, libsodium,
zeromq and zimg

In order to install ffmpeg, I had to install more than eighty additional dependency packages!

1
  • 1
    Wow! This worked perfectly on my first try on an ARM Mac to convert a webm file (which Quicktime does not support) Docker is the way. And thanks for useful example settings. Jul 20, 2023 at 18:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .