# How to install FFmpeg on MacOS

Posted 1 year ago
9014 Views
|
16 Replies
|
14 Total Likes
|

MODERATOR NOTE:
for installing FFmpeg on Linux see this post,
https://community.wolfram.com/groups/-/m/t/2188963
for installing on Windows see this post
https://community.wolfram.com/groups/-/m/t/2177967

# Introduction

In an earlier community post, Piotr explained how installing FFmpeg can improve codec support in the Wolfram Language and how to do it on Windows. Chien-Yu expanded on this in another community post to give detailed instructions for installing FFmpeg on Linux. Here I explain some details on how this can be done on MacOS. Let's begin with a recap of why this is important.

Video object and video processing functions were introduced in Wolfram Language 12.1. To read from and write to video files, video functionality uses media libraries provided by operating systems as well as a limited version of FFmpeg that is shipped with the language and can be immediately used. Details and examples showing how to import and export video files can be found in the Importing & Exporting Video tutorial. The Codec Support section in that tutorial describes the limitations of the FFmpeg shipped with the language and shows how installing the full version of FFmpeg gets you a better support for audio and video codecs.

Without FFmpeg installed, the first time a video function is called a message is displayed, suggesting to install FFmpeg for more complete codec support. Here is the list of supported video decoders available before having FFmpeg installed. At the end of this post we will compare the list with the supported decoders after FFmpeg is installed.

In[1]:= Length /@ $VideoDecoders During evaluation of In[1]:= General::sysffmpeg: Using a limited version of FFmpeg. Install FFmpeg to get more complete codec support. Out[1]= <|"AVI" -> 37, "Matroska" -> 55, "MP4" -> 13, "Ogg" -> 1, "QuickTime" -> 23, "VideoFormat" -> 83|>  Before proceeding, ensure the latest version of FFmpegTools is installed by evaluating the following: PacletInstall["FFmpegTools"]  # A note on Apple Silicon Macs Current versions of WL run using the Rosetta 2 technology on M1 Macs. Thus, it is necessary to install an Intel-based version of FFmpeg to use with Wolfram Language. Future versions of Wolfram Language will use the M1 chip natively and thus may require slightly different instructions. # Installing from a Package Manager ### For Intel mac computers: Installations of FFmpeg from Homebrew (brew.sh) and MacPorts (www.macports.org) are supported. To install FFmpeg via brew, follow the installation instructions at brew.sh. Then run the following to install FFmpeg: brew install ffmpeg@4  ### For Apple Silicon mac computers: The installation instructions on brew.sh for ARM computers installs software that won't work with WL 12.2.0 by default. To install an Intel-compatible version of brew, paste the instructions at brew.sh to install in place of <brew-install>, then run the following commands: arch -x86_64 <brew-install> arch -x86_64 /usr/local/bin/brew install ffmpeg@4  # Using an existing FFmpeg installation Note this is for power users only and is not typically required or encouraged. This strategy works for both Intel and ARM based macs provided a compatible version of FFmpeg is installed. If FFmpeg is installed in a location other than the standard location installed by Homebrew or MacPorts, admin users can create symbolic links in /opt/Wolfram/ffmpeg/$SystemID/current (e.g. /opt/Wolfram/ffmpeg/MacOSX-x86-64/current). $SystemID can be obtained by evaluating $SystemID in the Wolfram Language.

The next few commands can be run in a terminal to create symbolic links in the correct directory after modifying ffmpegdir to the correct path the existing ffmpeg installation is located. For example, if ffmpeg is installed in /path/to/ffmpeg, the following creates symlinks in /opt/Wolfram/ffmpeg/MacOSX-x86-64/current:

ffmpegdir="/path/to/ffmpeg"
sudo mkdir -p "$linkdir" && for dep in libavcodec.58 libavformat.58 libavutil.56 libavfilter.7 libswscale.5 libswresample.3; do find "$ffmpegdir" -type f -name '*'"$dep"'*dylib' -exec sudo ln -sf '{}' "$linkdir/$dep.dylib" \; ; done  If a different installation of ffmpeg should be used by a specific version of Wolfram Language on your system, /opt/Wolfram/ffmpeg/$SystemID/version is also supported (e.g. /opt/Wolfram/ffmpeg/MacOSX-x86-64/12.2.0). Simply change current to the 3 digit version number being targeted. The paths that Wolfram Language version 12.2 will search on for FFmpeg are (in order):

/opt/Wolfram/ffmpeg/MacOSX-x86-64/12.2.0
/opt/Wolfram/ffmpeg/MacOSX-x86-64/current
/usr/local/lib
/opt/local/lib


# Final note

Once FFmpeg is installed via any of the methods previously described, restart Wolfram Language. When you evaluate $VideoDecoders again, you should see the list that contains many codecs not available before: In[1]:= Length /@$VideoDecoders

Out[1]= <|"AVI" -> 160, "Matroska" -> 260, "MP4" -> 34, "Ogg" -> 1,  "QuickTime" -> 70, "VideoFormat" -> 327|>


Another way to confirm that the full version of FFmpeg is used by Wolfram Language:

In[2]:= FFmpegTools$SystemFFmpegQ Out[2]= True  16 Replies Sort By: Posted 1 year ago  The Windows version of this post can be found hereThe Linux version of this post can be found here Posted 1 year ago  -- you have earned Featured Contributor Badge Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you! Posted 1 year ago  With both the ARM and x86 versions of Homebrew installed it does not work. But using the symbolic links to point to the x86 version solved the issue. Posted 1 year ago  Hi Christophe, was the x86 brew install of ffmpeg installed to /usr/local/lib? what do you get for this? ls -ls /usr/local/lib/libavc* Posted 1 year ago  I have the x86 homebrew in /usr/local and the ARM homebrew in /opt/homebrewls -ls /usr/local/lib/libavc*is giving nothing :-) It is empty.But I have the lib here: /usr/local/opt/ffmpeg/lib/libavcodec.58.91.100.dylibAnd by creating the symbolic links to that place, everything is working.At least, I see the list of codecs in $VideoDecoders and FFmpegTools\$SystemFFmpegQ is returning True.It is not a problem for me. But I wanted to share just in case other people may have similar issues. I have not yet tested if the encoding is working.I have followed your instructions to install the x86 version of home-brew and ffmpeg. I have done nothing special.
Posted 1 year ago
 I'm glad it's working for you with the symlinks, but I'm surprised the x86 brew would install to anywhere aside from /usr/local/Cellar with a symlink in /usr/local/lib. In case this helps other users, can you please confirm if the x86 brew is installed to /usr/local/bin/brew?
Posted 1 year ago
 I have /usr/local/bin/brew. Don't know how to check if this executable is x86 or arm.I don't have the symlinks in /usr/local/lib pointing to ffmpeg in Cellar.But I do have ffmpeg in /usr/local/Cellar.The /usr/local/opt/ffmpeg is a symlink to the version in /usr/local/Cellar.So in short : it looks like /usr/local/lib was not used but instead it is /usr/local/opt/ffmpeg.I do see some codecs in /usr/local/lib like libvorbisenc.aBut the libavcodec.58 libavformat.58 libavutil.56 libavfilter.7 libswscale.5 libswresample.3 are in the ffmpeg folder.
Posted 1 year ago
 /usr/local/Cellar sounds right but I have no idea why it would have put the symlinks in usr/local/opt/ffmpeg. When I tried this on a m1 mac last week arch -x86_64 /usr/local/bin/brew install ffmpeg created symlinks in /usr/local/lib like brew usually does. I'd be curious to see what arch -x86_64 /usr/local/bin/brew reinstall ffmpeg looked like in terms of install locations in the brew output.
Posted 1 year ago
 I have made the reinstall. I think I understand what the problem was.I already had a ffmpeg in /usr/local/bin (don't ask me why ... I don't know).The installer told me it could not create a symlink because of this and as consequence the symlinks for the libraries were not created.I removed the binary I had. I made a reinstall again and now it looks like all the libraries are symlinked in /usr/local/lib.So, next time : I'll read the output of the homebrew installer because I probably got the same warning the first time I installed the x86 version.I'll test later if it works when I have removed the other symlinks I had created.
Posted 1 year ago
 Thank you so much for confirming this, I just wanted to make sure that the typical arch -x86_64 /usr/local/bin/brew install ffmpeg still works as expected.
Posted 1 year ago
 In 12.3, there is a nice dialog box that comes up and tells me how to install ffmpeg with MacPorts:Clicking the command copies it.The problem is that it copies the wrong command. The clipboard will contain sudo port install ffmpeg + gpl3 + nonfree, which is incorrect and does not work as intended. There must be no spaces after the + signs. The correct command is sudo port install ffmpeg +gpl3 +nonfree (which is what is displayed, but is not what is copied).
Posted 2 months ago
 I saw different approaches to using FFmpeg on a M1 Mac, but none have worked so far. With 13.0.1 and brew install ffmpeg or brew install ffmpeg@4 Mathematica refuses to find the FFmpeg installation. It's installed in /opt/homebrew/Cellar and links are present in /opt/homebrew/bin/ and /opt/homebrew/lib/. I think M13.0.1 is fully compatible with ARM Macs so a x86-installation shouldn't be necessary, right?
Posted 1 month ago
 After Homebrew automatically upgraded ffmpeg v4 to v5 I found that Mathematica could no longer find the extra codec files on my Intel Mac running OSMonterey 12.3. To resolve the issue I had to do the following in Homebrew terminal: brew uninstall ffmpeg brew install ffmpeg@4 brew link ffmpeg@4 The first line removes ffmpeg v5.The second line installs ffmpeg v4. The last line is critical as it installs the symlinks that Mathematica needs to find ffmpeg. These symlinks are NOT installed automatically when Homebrew installs ffmpeg v4 because this version is now considered outdated. Evidently, Mathematica 13.0.1 is not currently compatible with ffmpeg v5; at least I couldn't find a way to make it work.Good luck!
Posted 1 month ago
 Thanks! That also worked on a M1 Mac! It seems some of the calls from Mathematica to FFmpeg are hardcoded and not dynamic, that's unfortunate.Thank you very much!
Posted 1 month ago
 Thanks for confirming this workaround! We're working hard to make FFmpeg work as out of the box as possible.
Posted 14 days ago
 Sean, I noticed that libavdevice.58 is missing in your list of links that need to be created manually! With this addition, your script works with Mathematica 13.0.1 under MacOS x86. Many thanks :)