Dev:Doc/Building Blender/Mac/FFMPEG

提供: wiki
移動先: 案内検索

Building Blender on OS X with FFMPEG

There are two ways of building Blender on OS X with FFMPEG. The simpler method, using MacPorts, is straightforward and involves minimum hassle; the manual route allows for greater control over options enabled during compile time.

The Simple Route

This assumes that you already have MacPorts installed. Make a note of the folder where MacPorts installs all the libraries/include files it builds(usually it is /opt/local/ ). If you had the terminal window running during the installation of MacPorts, restart it so it can update the path, otherwise, you'll get a "port: command not found" error.

First, install ffmpeg via MacPorts; it will fetch the sources for you and compile with standard options.

sudo port install ffmpeg

Once port does its thing, copy "blender/build_files/scons/config/" to the root directory as and find the following lines.

# enable ffmpeg  support
BF_FFMPEG = LIBDIR + '/ffmpeg'
BF_FFMPEG_INC = "${BF_FFMPEG}/include"
BF_FFMPEG_LIB = 'avcodec avdevice avformat avutil mp3lame swscale
x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg bz2'
#bz2 is a standard osx dynlib

Change this to the following:

# enable ffmpeg  support
BF_FFMPEG = '/opt/local' #LIBDIR + '/ffmpeg'
# This is the folder where port installed ffmpeg to
BF_FFMPEG_INC = "${BF_FFMPEG}/include"
# Note that in the line below 'faac faad' is added
BF_FFMPEG_LIB = 'faac faad avcodec avdevice avformat avutil mp3lame swscale
x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg bz2'
#bz2 is a standard osx dynlib

Note the two lines starting 'BF_FFMPEG = ..." and "BF_FFMPEG_LIB = 'faac faad...' " and compare them with the previous code; the changes are made in these two lines only. Now, fire up scons:

python scons/ -j 2

The '-j 2' parameter is optional and is used to speed up builds in multi-core systems.

The Advanced Route


Recently (as of blender revision r26894) Blender switched to using the system FFMPEG instead of using the libraries included in the SVN source. This is a better system, but can make building blender confusing now. The following steps are what I took to get it working, however I can not guarantee that this will work for you. I hope that you will be able to at least get some ideas of what to do from these steps.

Please note this this is not the minimal setup. I wanted to have several options available to me under FFMPEG, so I chose to build with several enabled. According to the wikipage on FFMPEG on linux (which is very similar to the steps here) the required libraries "are libavcodec-dev, libavdevice-dev, libavformat-dev, libswscale-dev, and libavutil-dev by default."

First Step: Setting up the folder structure

Begin by opening a terminal window. Navigate to a directory where you would like to put the folder in which all the files we will be building will be placed. For me I chose my documents directory. Next, you will want to make a new directory. You may call it whatever you want, but to prevent frustration, avoid names with spaces or reserved characters, such as slashes (/ or \) or dollar signs ($). Once made, you will want to navigate into it. Here is my code.

cd ~/documents
mkdir Source_Codes
cd Source_Codes

That is it. Next, we will download all the sources we will need. Don't close your terminal window, as you will need it next, and navigating to your directory again will just take time.

Second Step: Downloading the sources

Ok, now we need to start getting the source files to build FFMPEG and the codec libraries it needs to build for blender. Start by bringing up your terminal (if you closed it, you will want to navigate back to that folder we made in the last step. Next, enter the following command into the terminal:

svn checkout svn:// ffmpeg

Now, let that process finish. You will now have a FFMPEG folder in the folder you made. The next few aren't quite as easy. You will have to go to the following websites, and download the source codes manually (usually they are in .tar, .tar.gz or .zip format.). If they download to your downloads folder, which they probably will if you haven't changed your download path in your internet app (I used safari). Decompress the files you downloaded, and copy/move them to the directory you made using finder. If they have long file names, you may choose to rename the folders to short names like libfaad, instead of leaving it as something like libfaad-1.1.0. Here are the library names, and the links to the pages they can be found at:

Libfaac + libfaad (
x264 (
xvidcore (
libogg (
libtheora (
libmp3lame (
libvorbis (

Once downloaded, decompressed, copy/moved, and optionally renamed, you are ready to begin the next step.

Third Step: Building all the libraries

Ok, the next step is to configure and build all the libraries. There are two methods we will be using, building using make, and building using xcode. If you do not have xcode installed, then install it first from the disks that came with your mac.

Using Xcode:

I found that only libogg needed built using xcode, the others built fine with make. So, in a finder window, navigate to the libogg folder in the folder you made. Inside, there will be a macosx folder.Run the xcodeproj file that is there. When xcode opens, go to the build menu, and click build.


Next, open up a terminal window. You will want to navigate to the folder where your source files are. Then the procedure is basically the same for all the remaining libraries (except for ffmpeg). You will run the following terminal commands in each libraries folder:

sudo make install

If you get an error, try running

sudo make

as I found that has sometimes solved the problem.

Do those previous commands in the folders for each of these libraries:

libtheora: Run ./configure, make, sudo make in this folder.	
faac: Run sh ./bootstrap, ./configure, make,sudo make install in this folder.
faad: Run sh ./bootstrap, ./configure, make, sudo make install in here too.
x264: Run ./configure, make, sudo make install here.
xvidcore: Run ./configure, make, sudo make install in the build/generic folder.
libmp3lame: Run ./configure, make, sudo make install in this folder.
libvorbis: Run ./configure, make, sudo make install here.

Note the difference with xvidcore. You have to run the commands in the build/generic folder.

Fourth Step: Moving Some Directories

Now, there may be an easier way to do this, but this is what worked for me. The new library files that the last step created need to be moved into the ffmpeg folder. You will probably want to do this with finder, but using the terminal is also possible. I will assume that if you choose to use terminal, you already know what you are doing. Here is a list of what folders to copy where:

  • libfaac/libfaad: Inside their folders are folders named libfaac and libfaad respectively. Copy these folders to the main ffmpeg directory.
  • Theora/Ogg: Copy the whole theora folder into the ffmpeg folder. This is probably not necessary, but I did not feel like finding out which of the few files I needed. Next, you want to copy the files from the macosx/build/Debug/ogg.framework/Versions/A directory in the libogg folder into the theora folder which you just moved into the ffmpeg folder.
  • x264: Copy this whole folder into the ffmpeg folder.
  • xvidcore: In this folder you want to copy the whole build folder (at /build/genaric/=build in the xvidcore folder) to the ffmpeg folder, and rename it something like libxvidcore.
  • libmp3lame: Copy the libmp3lame folder to the ffmpeg folder.
  • libvorbis: Copy the lib folder from the libvorbis build folder into the ffmpeg folder, and rename it something like libvorbis

Ok, once that is done, you only have two short steps to go!

Fifth Step: Building FFMPEG

Ok, finally. We get to build the program we have been wanting all this time! Open a terminal and navigate into the ffmpeg folder. You now have to run the commands we did for the other libraries, but the configure step is a little different.

We have to tell ffmpeg to build using the libraries we just built, so we have to pass some arguments along with the configure command. Try the following terminal command:

./configure --enable-nonfree --enable-gpl --enable-libmp3lame --enable-libfaad 
--enable-libx264 --enable-libtheora --enable-libfaac --enable-libxvid --enable-libvorbis

Please note that I hit "enter" between --enable-libfaad and --enable-libx264. If you cut and paste the code directly, I reccomend pasting it first into something like TextEdit, and removing the "enter" and then copy and pasting that code into the terminal.

If you don't get any errors, then yay! Run:

sudo make
sudo make install

I found that make often failed without sudo in front, but feel free to try without it first if you want. If all those go well, continue onto the final step, editing your

If the configure command failed for you, check what it gives for the reason of failure. If you get something that says "unknown option" and then lists an enable statement, then it means that you either tried to build ffmpeg with a library that it doesn't support (if you followed this tutorial exactly, then this should not be the case), or, more likely, you mistyped the statement. Check your spelling, and try again.

I unfortunatly cant reproduce it at the time of writing this tutorial, but sometimes it will give you an error saying it cant find a library. To try to fix this, make sure you followed the "moving some directories" step correctly.

Sixth and Final Step: Editing your file

Ok, the last step. Using finder, navigate to the directory where you build blender in. If you use scons to build, you should have a file called in the root of your folder. If not, and you are going to build using scons, copy the out of the config directory, and rename it to

Next, open the file in whatever you use to edit it. TextEdit should work, but I usually double click on the file, and it opens in a python editor that in built into python. Look through the file for a stanza about FFMPEG. It will look something like:

# enable ffmpeg  support
BF_FFMPEG = LIBDIR + '/ffmpeg'
BF_FFMPEG_INC = "${BF_FFMPEG}/include"
BF_FFMPEG_LIB = 'avcodec avdevice avformat avutil mp3lame swscale
x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg bz2'
#bz2 is a standard osx dynlib

You will be changing almost all the lines. Here is what they should be changed to:

#BF_FFMPEG = 'path_to_your_ffmpeg_executable'
#:Basically, this is the path to the location where you should have copied the libfolders in the fourth step.
#:You just need to remove the /include from the original line to get what I have above.
#:This is the same as the last one, but you are removing the /lib
#BF_FFMPEG_LIB = 'avcodec avdevice avformat avutil mp3lame faad faac swscale x264 xvidcore theora theoradec theoraenc vorbis vorbisenc vorbisfile ogg bz2'
#:All I did was add the two faad and faac parts to that line. I picked just a random spot in the list to add them.

Now, save the file, and try building blender. If you did everything right, it should build fine!