Compile and install FFmpeg from the source code in the Mac OS X Environment
Recently, due to a project requirement, real-time video codec needs to be developed, and FFmpeg is used for real-time video codec in x264 mode. In Windows and Linux environments, FFmpeg dynamic libraries, header files, and other resources are easily obtained, and the compilation environment is also easy to build. However, the development and compilation environments under Mac OS X are not that easy. By default, FFmpeg does not provide compiled Dynamic Link Libraries (or even static libraries) in Mac OS X, but other compiled FFmpeg executable programs are found on the Internet, unable to meet the compilation and connection requirements for the FFmpeg dynamic library (or static library) in the development process. Therefore, consider compiling and installing FFmpeg from the source code by yourself, to obtain the FFmpeg dynamic link library (and static library) version under Mac OS X, and build a development and compilation environment. First, make sure that the Mac OS X has a compilation and development environment. Generally, XCode and the corresponding Command line tools are installed. Then, download the source code of the latest FFmpeg version from the FFmpeg official website. You can directly download the packaged source code compressed file, or use git to obtain the complete source code image. We recommend that you use git. The command is as follows: git clone git: // source.ffmpeg.org/ffmpeg.git ffmpeg do not rush to start compilation and configuration immediately! The first thing to understand is that FFmpeg is a codec framework that supports different codecs and uses unified APIs for calling. However, by default, only the decoder for various media formats is provided (basically completely covered ), encoder provides a few open source formats by default (or formats without patent protection ). Therefore, if you need FFmpeg to support encoding in multiple media formats, you need to download and install the encoders (mainly by installing these encoders to obtain their header files, dynamic libraries, and static libraries for FFmpeg compilation ), in order to ensure that the binary code of these encoders is loaded during FFmpeg compilation, so that FFmpeg has these encoding functions. After comparison and analysis, as far as my project needs to be concerned, the encoder needs to download and install the following files: x264, fdk-aac, libvpx, libvorbis, and LAME (mp3) that's enough. Next, download the source code of x264, fdk-aac, libvpx, libvorbis, and LAME respectively, and then compile and install them separately. Note that it is best to force the -- enable-static and -- enable-shared parameters to generate static and dynamic libraries when you execute their respective configure to create the compilation configuration file. In addition, because it is compiled in the Mac OS X environment, after each compilation, you must execute sudo make install, install it to the corresponding location in the default/usr/local directory (/usr is not recommended for Mac OS X). Therefore, do not specify -- prefix in configure, use the default/usr/local directory prefix. After the encoder is installed, You can compile and install FFmpeg. Go to the FFmpeg source code directory and run the following command :. /configure -- prefix =/usr/local -- enable-gpl -- enable-nonfree -- enable-libfdk-aac -- enable-libmp3lame -- enable-libvorbis -- enable-libvpx -- enable-libx264 -- enable-static -- enable-shared make sudo make install to complete compilation and installation, the header file of FFmpeg will be copied to the corresponding location under/usr/local/include, and the static library and dynamic library will be copied to the/usr/local/lib directory, the executable programs (FFmpeg, ffprobe, and ffserver) of ffmpeg will be copied to the/usr/local/bin directory, so that the FFmpeg development environment is ready.. Note that, by default, Mac OS X does not have SDL. Therefore, when FFmpeg is compiled, SDL support cannot be detected and ffplay executable programs will not be compiled.