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"
linkdir="/opt/Wolfram/ffmpeg/MacOSX-x86-64/current"
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