Simple Things
Ink and Incapability
How to compile ffmpeg/mplayer for MacOSX
This guide shows how to build ffmpeg, ffmpeg (libav), mplayer and mencoder binaries on MacOSX.
See the bottom of this post for a revision history.
What you need before you start:
- Xcode
- Some patience
- Some experience in using a command line interface
Miscellaneous:
- yasm-1.2.0.tar.gz
- zlib-1.2.6.tar.gz
- bzip2-1.0.6.tar.gz
- git-1.7.3.5
Encoder/decoder media libraries:
- lame-3.99.5.tar.gz
- faad2-2.7.tar.bz2
- faac-1.28.tar.bz2
- xvidcore-1.3.2.tar.gz
- last_stable_x264.tar.bz2
- libogg-1.3.0.tar.gz
- libvorbis-1.3.3.tar.gz
- libtheora-1.1.1.tar.bz2
- gsm-1.0.13.tar.gz
- amrwb-7.0.0.3.tar.bz2
- amrnb-7.0.0.2.tar.bz2
- speex-1.2rc1.tar.gz
- flac-1.2.1.tar.gz
- libxavs (via subversion)
- vo-aacenc-0.1.1.tar.gz
- vo-amrwbenc-0.1.1.tar.gz
- libvpx-v1.0.0.tar.bz2
Encoder/decoder media programs:
- ffmpeg
- ffmpeg libav
- mplayer
Trying to compile versions obtained directly from the repositories may or may not break or require different configure flags. You can always try and using the stable release source code which should not require too many changes to the configure options.
This guide was written with MacOSX 10.6.x and Xcode 4.x in mind, for compiling on MacOSX 10.7 see compilation notes at the bottom of this posting.
Create the Ramdisk
VOLNAME=Ramdisk
DISK_ID=$(hdid -nomount ram://26214400)
newfs_hfs -v ${VOLNAME} ${DISK_ID}
diskutil mount ${DISK_ID
Create some shortcuts
export MES=/Users/snowy/tmptmp/mediaencoding/base/
export TARGET="/Volumes/${VOLNAME}/"
export CMPL="/Volumes/${VOLNAME}/compile"
export PATH=${TARGET}/bin:$PATH
mkdir ${CMPL}
Building yasm
cd ${CMPL}
tar xzpf ${MES}/yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure --prefix=${TARGET}
make -j 2 && make install
Building git
cd ${CMPL}
curl -O http://kernel.org/pub/software/scm/git/git-1.7.3.5.tar.bz2
tar xjpf git-1.7.3.5.tar.bz2
cd git-1.7.3.5
./configure --prefix=${TARGET}/git
make && make install
PATH=${TARGET}/git/bin:$PATH
Building lame
cd ${CMPL}
tar xzpf ${MES}/lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install
Building faad
cd ${CMPL}
tar xjpf ${MES}/faad2-2.7.tar.bz2
cd faad2-2.7
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install
Building faac
cd ${CMPL}
tar xjpf ${MES}/faac-1.28.tar.bz2
cd faac-1.28
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install
Building xvidcore (and removing the dynamic library)
cd ${CMPL}
tar xzpf ${MES}/xvidcore-1.3.2.tar.gz
cd xvidcore
cd build/generic
./configure --prefix=${TARGET}
make -j 2 && make install
rm ${TARGET}/lib/libxvidcore.4.dylib
Building x264
cd ${CMPL}
curl -O ftp://ftp.videolan.org/pub/videolan/x264/snapshots/last_stable_x264.tar.bz2
tar xjpf last_stable_x264.tar.bz2
cd x264*stable
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install && make install-lib-static
Building ogg
cd ${CMPL}
tar xzpf ${MES}/libogg-1.3.0.tar.gz
cd libogg-1.3.0
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install
Building vorbis
cd ${CMPL}
tar xzpf ${MES}/libvorbis-1.3.3.tar.gz
cd libvorbis-1.3.3
./configure --prefix=${TARGET} --with-ogg-libraries=${TARGET}/lib --with-ogg-includes=${TARGET}/include/ --enable-static --disable-shared
make -j 2 && make install
Building theora
cd ${CMPL}
tar xjpf ${MES}/libtheora-1.1.1.tar.bz2
cd libtheora-1.1.1
./configure --prefix=${TARGET} --disable-asm --with-ogg-libraries=${TARGET}/lib --with-ogg-includes=${TARGET}/include/ --with-vorbis-libraries=${TARGET}/lib --with-vorbis-includes=${TARGET}/include/ --enable-static --disable-shared
make -j 2 && make install
Building gsm
cd ${CMPL}
tar xzpf ${MES}/gsm-1.0.13.tar.gz
cd gsm-1.0-pl13
mkdir -p ${TARGET}//man/man3
mkdir -p ${TARGET}//man/man1
perl -p -i -e "s#^INSTALL_ROOT.*#INSTALL_ROOT = $TARGET#g" Makefile
perl -p -i -e "s#_ROOT)/inc#_ROOT)/include#g" Makefile
make -j 2 && make install
Building amrwb (downloads additional sources)
cd ${CMPL}
tar xjpf ${MES}/amrwb-7.0.0.3.tar.bz2
cd amrwb-7.0.0.3
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install
Building amrnb (downloads additional sources)
cd ${CMPL}
tar xjpf ${MES}/amrnb-7.0.0.2.tar.bz2
cd amrnb-7.0.0.2
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install
Building speex
cd ${CMPL}
tar xzpf ${MES}/speex-1.2rc1.tar.gz
cd speex-1.2rc1
./configure --prefix=${TARGET} --with-ogg-libraries=${TARGET}/lib --with-ogg-includes=${TARGET}/include/ --enable-static --disable-shared
make -j 2 && make install
Building flac
cd ${CMPL}
tar xzpf ${MES}/flac-1.2.1.tar.gz
cd flac-1.2.1
./configure --prefix=${TARGET} --disable-asm-optimizations --disable-xmms-plugin --with-ogg-libraries=${TARGET}/lib --with-ogg-includes=${TARGET}/include/ --enable-static --disable-shared
make -j 2 && make install
Building xavs
cd ${CMPL}
svn co https://xavs.svn.sourceforge.net/svnroot/xavs xavs
cd xavs/trunk
./configure --prefix=${TARGET} --disable-asm
make -j 2 && make install
Building vo-aaenc
cd ${CMPL}
tar xzpf ${MES}/vo-aacenc-0.1.1.tar.gz
cd vo-aacenc-0.1.1
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install
Building vo-amrwbenc
cd ${CMPL}
tar xzpf ${MES}/vo-amrwbenc-0.1.1.tar.gz
cd vo-amrwbenc-0.1.1
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install
Building libvpx
cd ${CMPL}
tar xjpf libvpx-v1.0.0.tar.bz2
cd libvpx-v1.0.0
./configure --prefix=${TARGET} --as=yasm --disable-shared --enable-static --enable-vp8
make -j 2 && make install
Building zlib
cd ${CMPL}
tar xzpf ${MES}/zlib-1.2.6.tar.gz
cd zlib-1.2.6
./configure --prefix=${TARGET} --static
make -j 2 && make install
Building bzip2
cd ${CMPL}
tar xzpf ${MES}/bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make
make install PREFIX=${TARGET}
Up to here, the compilation path for ffmpeg, ffmpeg (libav) and mplayer are the same.
Now you can build either ffmpeg, libav’s ffmpeg or mplayer.
Building ffmpeg
cd ${CMPL}
git clone git://git.videolan.org/ffmpeg.git
cd ffmpeg
export LDFLAGS="-L${TARGET}/lib $CFLAGS"
export CFLAGS="-I${TARGET}/include $LDFLAGS"
./configure --prefix=${TARGET} --as=yasm --extra-version=snowy --disable-shared --enable-static --disable-ffplay --disable-ffserver --enable-gpl --enable-pthreads --enable-postproc --enable-gray --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-libspeex --enable-bzlib --enable-zlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libxavs --enable-nonfree --enable-version3 --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvpx
make -j 2 && make install
Building libav’s ffmpeg
cd ${CMPL}
git clone git://git.libav.org/libav.git
cd libav
export LDFLAGS="-L${TARGET}/lib $CFLAGS"
export CFLAGS="-I${TARGET}/include $LDFLAGS"
./configure --prefix=${TARGET} --as=yasm --extra-version=snowy --disable-shared --enable-static --enable-gpl --enable-pthreads --enable-gray --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-libspeex --enable-bzlib --enable-zlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libxavs --enable-nonfree --enable-version3 --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvpx
make -j 2 && make install
Building mplayer/mencoder
If you do not want mplayer/mencoder to make use of X11, simply rename /usr/X11/include prior to configure/make (and do not forget to revert the change after the build was successful)
If Xcode 4.x is installed, mplayer/mencoder will not link successfully and thus the gcc-4.2/g++-4.2 from Xcode 3.x has to be used to compile and link mplayer/mencoder.
if [ -e /Developer-old ] then export CC=/Developer-old/usr/bin/gcc-4.2 export CXX=/Developer-old/usr/bin/g++-4.2 fi
And the actual mplayer/mencoder compilation step
cd ${CMPL}
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
cd mplayer
./configure --prefix=${TARGET} --extra-cflags="-I${TARGET}/include/" --extra-ldflags="-L${TARGET}/lib"
make -j 2 && make install
After a successful run, you should be able to just grab the ffmpeg or
mplayer/mencoder binaries from ${TARGET}/bin and use them :)
If ffmpeg/libav fails to build resulting in the following error:
libswscale/x86/yuv2rgb_mmx.c: In function 'ff_yuv2rgb_init_mmx': libswscale/x86/yuv2rgb_mmx.c:77: error: 'yuv420_rgb24_MMX2' undeclared (first use in this function) libswscale/x86/yuv2rgb_mmx.c:77: error: (Each undeclared identifier is reported only once libswscale/x86/yuv2rgb_mmx.c:77: error: for each function it appears in.) libswscale/x86/yuv2rgb_mmx.c:78: error: 'yuv420_bgr24_MMX2' undeclared (first use in this function)
Execute the following lines to fix a spelling(?) mistake(?) in the source code prior to running configure and make:
perl -p -i -e "s/24_MMX2/24_MMX/g" libswscale/x86/yuv2rgb_mmx.c perl -p -i -e "s/HAVE_MMX2/HAVE_MMX/g" libswscale/x86/yuv2rgb_mmx.c perl -p -i -e "s/AV_CPU_FLAG_MMX2/AV_CPU_FLAG_MMX/g" libswscale/x86/yuv2rgb_mmx.c
Compilation notes for compiling on MacOSX 10.7.x using Xcode 4.2.x
ffmpeg/libav:
- Compiler
Set export CC=clang as the very first step so everything is being compiled by clang - Ramdisk
Use ram://2097152 unless you want to create a really, really big RamDisk - zlib library
Remove the lib/libz.so* files which are being created for some unknown reason.. - configure flags
Add the –disable-asm flag when running configure for ffmpeg/libav
mplayer/mencoder:
- Compiler
Set export CC=clang as the very first step so everything is being compiled by clang
Compilation notes for compiling on MacOSX 10.7.x using Xcode 4.3.x
- Compiler
If “upgrading” from Xcode 4.2.1 to Xcode 4.3 things will break. Especially if /Developer was moved to trash as Xcode 4.3 suggests you should do.
Prior to upgrading to XCode 4.3 uninstall XCode 4.2.1 using ‘sudo /Developer/Library/uninstall-devtools –mode=all’.
After this has succeeded, install Xcode 4.3 from the App Store and then download the command line tools from within XCode (Prefernces->Downloads->Command Line Tools) - libvpx
The build will break with Xcode 4.3. Prior to executing ./configure, set the following:
export CFLAGS=-I/usr/include
export LDFLAGS=-L/usr/libAfter the ‘make install’, unset both variables again:
unset CFLAGS
unset LDFLAGS
Revision history:
[Updated 21/04/2012]: Updated zlib to 1.2.6
[Updated 02/03/2012]: Updated lame to 3.99.5
[Updated 18/02/2012]: Added libvpx compilation hints when using Xcode 4.3
[Updated 10/02/2012]: Updated libvorbis to 1.3.3, using libvpx v1.0.0 instead of git repository
[Updated 29/01/2012]: Updated lame to 3.99.4
[Updated 20/12/2011]: Added libvpx
[Updated 19/12/2011]: Hints about compiling on 10.7.x (Lion)
[Updated 13/12/2011]: Updated yasm to 1.2.0, fixed a spelling mistake
[Updated 23/10/2011]: Updated lame to 3.99
[Updated 25/09/2011]: Updated libogg to 1.3.0
[Updated 16/09/2011]: libav does not support –disable-ffplay and –disable-ffserver anymore
[Updated 06/08/2011]: Added vo-aacenc and vo-amrwbenc
[Updated 28/07/2011]: Added libxavs, cleaned up the article a little
[Updated 23/06/2011]: x264 requires an extra make install command for the library and include files
[Updated 03/06/2011]: Provided compilation workaround for ffmpeg/libav
[Updated 01/06/2011]: Updated Xvid to 1.3.2
[Updated 29/03/2011]: Added libav compilation hint
[Updated 26/03/2011]: Updated Xvid to 1.3.1, new ffmpeg git location, Xcode 4 hint for mplayer
[Updated 24/02/2011]: Updated Xvid to 1.3.0, yasm to 1.1.0
[Updated 12/02/2011]: mplayer wants to download ffmpeg via git
[Updated 23/01/2011]: ffmpeg is now being obtained via git, updated libvorbis and libogg
[Updated 28/11/2010]: Fixed zlib static compilation, added a hint for X11 mencoder/mplayer
[Updated 21/09/2010]: Updated bzip2 version and ffmpeg-svn configure options
[Updated 20/06/2010]: Updated some libaries/components
[Updated 20/02/2010]: Recent tarballs of x264 do not require –enable-static –disable-shared configure options
[Updated 06/09/2009]: Using more recent library versions. Can compile on Snow Leopard
[Updated 09/12/2009]: You can also visit EvalVid for static ffmpeg binaries (MacOS X/Win32/Linux)
Everything great except the sed trick on libgsm which did not work for me. I had to manually edit Makefile
I was even able to compile SVN version removing –disable-vhook and –enable-swscale
THANKS!!!
Good point. I have used gnu sed 4.1.5 instead of the /usr/bin/sed supplied by Apple. I will add a note to the compilation process.
Hexeract I’ve got an issue as well with GSM following your instructions. I receive:
perl -p -i -e “s#_ROOT)/inc#_ROOT)/include#g” Makefile
Unmatched ) in regex; marked by <– HERE in m/_ROOT) <– HERE /inc/ at -e line 1.
Thanks
Try using: perl -p -i -e “s#_ROOT\)/inc#_ROOT)/include#g” Makefile
This is fantastic! I too had an issue with GSM but I didn’t need it anyway. This exactly what I needed to figure out how to compile a Mac binary. Thanks for the tutorial. I have spent hours digging to find the info you have provided in a simple format.
I was trying to do the same but get some errors, then I found this article and works great (I have some troubles with lame lib, so not included)
I only have one issue, X264 has some preset files that need to be placed somewhere, but I don’t know where with your method, the common place is “/usr/share/ffmpeg/”
I was trying with the latest builds before but I get this error:
dyld: Library not loaded: /usr/local/lib/libfaac.0.dylib
with your guide I get this error:
dyld: Library not loaded: /usr/local/lib/libmp3lame.0.dylib
that’s why I dissable libmp3lame and get it to work well, but without pressets.
I have all the files I use here:
http://www.rodrigopolo.com/ffmpeg/osxcompile/
Can you update your guide to work with the latests code, libmp3lame and x264 presets. thanks for the great job, help and for sharing!!!
The preset files simply go to $HOME/.ffmpeg/
The guide, when followed exactly step by step, should result in static builds of ffmpeg or mplayer/encoder.
You can, however, update the libraries you unpack and compile.
I recompiled using xvidcore-1.2.2.tar.gz and x264-snapshot-20090528-2245.tar.bz2 without any troubles.
Reading your file config_and_errors.txt the error is quite obvious:
You are not using a sandbox to install to and use to link against.
From what I suspect, both on MacOSX and Ubuntu, you simply did not use the –prefix=
option of ./configure and hence everything was installed into /usr/local.
For some odd reason you also built the shared libraries which, when you finally
compiled ffmpeg, it happily linked against in /usr/local/include and /usr/local/lib.
The resulting binary, when transferred to another box, will fail as shown.
Setting up $TARGET and using it as an option for –prefix in the ./configure run
is a very vital technique for this guide (and the success).
Checking your ffmpeg binary shows:
$ otool -L ffmpeg
ffmpeg:
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.4)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
/usr/local/lib/libfaac.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/lib/libfaad.2.dylib (compatibility version 3.0.0, current version 3.0.0)
/usr/local/lib/libmp3lame.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
The resulting ffmpeg binary, if you followed the guide step by step, looks like this:
$ otool -L ffmpeg
ffmpeg:
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.4)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
Does this information help you?
If all fails, I can provide you with a working ffmpeg (and mplayer/mencoder).
And the Ramdisk volume after a successful run.
Thanks a lot, I finllay did it, I’m making the compilation on Mac OS X on a MacBook Pro, I post my issues compiling on the FFmpeg user list and they give me this wonderfull link:
http://www.tkn.tu-berlin.de/research/evalvid/
Check it out, it hast all what FFmpeg can have!!! I will make a “FFmpeg H.264 AAC Injected FLV” guide to use a plug-in for wordpress I’m making, so I will post it here so you can check it out.
Thanks for the great guide. Everything worked fine except the mplayer/mencoder build. Grabbing teh latest snapshot and using your config – it appears they made some changes and this is no longer recognized:
–with-extraincdir=${TARGET}/include/ –with-extralibdir=${TARGET}/lib
instead I was able to use:
–extra-libs=${TARGET}/lib
but there seems to be no equivalent for the –extra-inc.
Attempting to compile yields:
In file included from liba52/imdct.c:725:
liba52/imdct_3dnow.h: In function ‘fft_asmb_3dnow’:
liba52/imdct_3dnow.h:257: error: can’t find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
make: *** [liba52/imdct.o] Error 1
oh well.. great job detailing rest of process.
Try the following when compiling from the subversion trunk:
$ cd /Volumes/Ramdisk/compile/
$ svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
$ cd mplayer
$ ./configure –prefix=/Volumes/Ramdisk/sw –extra-cflags=”-I/Volumes/Ramdisk/sw/include” –extra-ldflags=”-L/Volumes/Ramdisk/sw/lib/”
MPlayer SVN-r29404-4.0.1
MEncoder SVN-r29404-4.0.1
Thanks for the reply – unfortunately still failed. It looks like its tryingto find something to do with a52 – could it be that a52 libs need to be compiled first? I’m gonna try that – I’ll let you know…
— cut —
cc -Wundef -Wdisabled-optimization -Wno-pointer-sign -Wdeclaration-after-statement -std=gnu99 -I/Volumes/Ramdisk/sw/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -Ilibdvdread4 -mdynamic-no-pic -falign-loops=16 -shared-libgcc -I. -I/Volumes/Ramdisk/sw/include -I/usr/X11/include -I/usr/X11/include/freetype2 -I/usr/X11/include -c -o libass/ass.o libass/ass.c
In file included from liba52/imdct.c:725:
liba52/imdct_3dnow.h: In function ‘fft_asmb_3dnow’:
liba52/imdct_3dnow.h:257: error: can’t find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
make: *** [liba52/imdct.o] Error 1
make: *** Waiting for unfinished jobs….
BOOM! Got mplayer to compile. Reference: http://lists.mplayerhq.hu/pipermail/mencoder-users/2009-April/010240.html
Using this config:
./configure –prefix=${TARGET} –extra-cflags=”-I${TARGET}/include -O3 -fomit-frame-pointer” –extra-ldflags=”-L${TARGET}/lib/” –disable-vdpau && make -j 4 && make install
Note I also had previously compiled liba52 into the sandbox – but not sure if that had anything to do with the success or not.
When researching your problem, I have read that using –disable-vdpau will avoid the error but the main problem may be with the gnu compiler version used.
MPlayer really likes to choose its own compiler flags, I would not add any compiler specific options to the –extra-cflags, it will most likely break the compilation.
Can you provide the shell script you used to compile and where it breaks?
I just tried to reproduce your compilation error but could not do so.
The only changes to the above guide are the usage of:
– yasm-0.8.0.tar.gz
– x264-snapshot-20090528-2245.tar.bz2
– xvidcore-1.2.2.tar.gz
But that should not have any effect on the compilation of a52…
Yes the research I read also indicated the vdpau and the compiler could be the problem. I disabled vdpau first but that had no effect, it was only after add the “-O3 -fomit-frame-pointer” was I able to complete the mplayer compilation. I am aslo using a bit newer components than in your guide:
-yasm-0.8.0.tar.gz
-x264-snapshot-20090625-2245.tar.bz2
-xvidcore-1.2.1.tar.gz
I tried xvidcore-1.2.2 but there were some errors in its compilation so I dropped back to the one listed in your guide and it worked fine.
BTW – your guide and use of the ram disk and sandbox has revolutionized the way I compile now. I am just a tinkerer, but I have always wanted to build stuff in a “sandbox” type layout I just never knew how. Your guide worked so well, I actually used it on my Ubuntu box and build a fresh static copy of ffmpeg for it using your technique. Thank you VERY MUCH for this detailed guide – it has been a real eyeopener!
Thank you very much, I am glad the guide was helpful!
xvidcore-1.2.2 should compile fine, as I used that when I tried to build mplayer from the SVN repository.
This is the compiler I used: gcc version 4.0.1 (Apple Inc. build 5490)
Using gcc 4.2 (gcc version 4.2.1 (Apple Inc. build 5566)) works too, but produces slightly larger binaries…
Hey you might be onto something there – just checked and I have gcc version 4.0.1 (Apple Inc. build 5465). I was unaware of a gcc update – I assumed those would be pulled in with the standard SystemUpdate utility – but apparently not – logging in now to ADC to see if I can find an update.
If you get errors encoding with mp3 and lame like this:
[libmp3lame @ 0x103a600]lame: output buffer too small (buffer index: 9405, free bytes: 387)
Audio encoding failed
Downgrade to the lame-3.98 (instead of lame-3.98.2) source code and recompile ffmpeg.
Note the errors are erroneous, as the output does indeed include properly encoded audio – it just issues those warnings.
for snow leopard, i had to use ./configure –enable-static –disable-shared CFLAGS=”-arch i386″ to compile xvidcore
Weird, when I (re)compiled everything on Snow Leopard it failed at libtheora (which needed a –disable-asm configure flag)
I used the gcc 4.2.1 shipping with Snow Leopard’s XCode 3.2
There is an error in the “libvorbis” part…
The option:
–with-ogg-includes=/Volumes/Ramdisk/sw/include/
Should be:
–with-ogg-includes=${TARGET}/include/
I got a great OS X Compilation ( http://rod.gs/Ml ) But now I’m trying to build one on Ubuntu, if I enable libvorbis I have all kind of issues, without it it works perfect, I’m very tired trying to do this, I’m willing to pay some one who want to build a static version like this but with ubuntu 9.04 (x32 and x64)
You are right, I have corrected this in the blog enttry.
Thank you for pointing this out to me!
For Ubuntu, you do not need to create a RamDisk, you can simply replace /Volumes/Ramdisk with a directory of your choice.
I will update the posting to reflect my currently
used setup on how to build ffmpeg/mplayer.
I only got as far as the xvidcore which craps out with this error:
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [libxvidcore.4.dylib] Error 1
I’m just using whatever the current version of XCode is for Snow Leopard. All I really want is a mencoder and a mplayer binary. Can someone smarter than me hook me up?
If you have followed the guide, you should have deleted the libxvidcore.4.dylib after compiling and installing xvidcore.
This will force the ffmpeg/mplayer/mencoder binary to be linked against the static version of xvidcore.
Do no hesitate to contact me if you need further assistance.
$ cd ${CMPL}
$ tar xzpf ${MES}/xvidcore-1.2.2.tar.gz
$ cd xvidcore
$ cd build/generic
$ ./configure --prefix=${TARGET} --disable-shared --enable-static
$ make -j 4 && make install
$ rm ${TARGET}/lib/libxvidcore.4.dylib
I didn’t get that far… xvidcore doesn’t build – stops with that error.
Checking your xvidcore output log, I can only guess it may have to do with the fact you have an i7
and neither yasm nor gcc 4.2.1 can produce good/proper assembly code.
In that case, try to just use make without the “-j 4″ option.
If that does not help, try adding the “–disable-assembly” switch and see if that resolves the issue.
Uggg,
This did not work on my i7 either. I tried the above suggestions.
You might want to put a note at the top that this won’t work yet for i7′s. I spent a couple hours trying this out of desperation.
I have been using mplayer to make videos of computer simulations for work and I just got this new machine and now I can’t run my code.
If anyone has any suggestions on how to run mencoder on an i7 please let me know. Thank You!
Have you tried compiling mplayer using the guide on your new machine? What went wrong and where?
If that does not help, try adding –enable-runtime-cpudetection option to the ./configure command line.
x264 compile fails
i get:
Unknown option –enable-static, ignored
Unknown option –disable-shared, ignored
No working C compiler found.
using snow leopard with gcc 4.2.1
all other components compile fine
Use 2 dashes/hyphens:
–enable-static –disable-shared
It is also very important you change your directory to xvidcore/build/generic where the configure script resides.
The c compiler gcc resides in /usr/bin/ so that should not really be a problem…
Hey very cool, and super helpful…
Though, the x264 doesn’t worth w/ double dashes.
$ ./configure –prefix=${TARGET} –disable-shared –enable-static
Unknown option –disable-shared, ignored
Unknown option –enable-static, ignored
I have just checked and you are right.
The configure in recent daily tarballs does not have the –enable-static or –disable-shared option anymore, default is to build a static version.
An update entry has been made to the posting, thank you for pointing this out to me.
Pingback: Man Vs Mkv: The Story So Far « Baud Attitude
Thank you. Great work. I needed a static build of ffmpeg with libmp3lame statical linked in ffmpeg on linux. I picked the the parts I needed and it worked out for me. This is the best page on the subject online!!! I did a lot of research before.
Thank you very much!
You can even build ffmpg from the subversion repository using yasm 1.0, lame 3.98.3 and updated xiph (vorbis/ogg) libraries,
if you are really into “bleeding edge” software versions :)
I want to thank you so much for this! I was pulling my hair out for hours trying to get a static build of FFmpeg and your guide was the only one that worked.
Also, great tip on using a ramdrive for the compilation. Really sped things up!
One thing I had to change though. I got an error about amrwb not being found even though I compiled it. It turns out they only support the opencore-amr project now and I got an error that that module was missing. I removed the amrwb and amrnb builds and compiled the latest git source of the opencore-amr project and it worked fine.
Other than that it was all smooth sailing :)
I am glad the guide was helpful.
When I recompile ffmpeg myself I sometimes have to tweak the ./configure line but mostly I just drop an option or check if an option has been renamed.
Hello,
Excellent guide you have I’ve been using it for some time. Got a question though maybe you can help…I have a .flv video that will not properly convert using a recent mencoder build I did according to your guide. However a mencoder build from last year that I did not compile myself converts the video perfectly and I can’t figure out why. I’m thinking it’s the way it was built but I don’t know how to find the differences? Anyways I can post more details here if you wish or if you would like to send me an email I could chat with you there. Thanks again for the great guide!
rc
It is very difficult to say what may have gone wrong withouth either knowing the source video or the encoding options used.
I doubt it is a problem the way it is built but it depends audio/video encoding options used (and thus on the libraries).
Other than that you might want to check the projects homepage for each codec for newer versions and try a recompile with more recent libraries.
As I am not really a video encoding expert I can not really help you with any “magic” audio/video encoding hints.
Better to ask on the mplayer mailing list MEncoder-users as described on the mplayer homepage.
Hey thanks for the reply! Yes I know you would need more info and actually I did post on the forums but they couldn’t tell me too. It might have just been some random bad video. Actually the issue was with the built-in demuxer (lavf) and seemed the problem it was reading the original video at close to 60fps when it was really close to 30fps. This seemed to throw off the whole encoding (at least that’s my guess) and I couldn’t figure out why an old mencoder build read it correctly and my newer one didn’t. Anyways I appreciate the reply and I’ll keep checking. Thanks again!
rc
Hello again,
I have another question that I’m thinking you might know the answer. Using your guide I have encountered the following error on a different Mac:
Dyld Error Message:
Library not loaded: /usr/X11/lib/libfreetype.6.dylib
Reason: image not found
I know this is a static build that should just work and the only thing I have added in addition to the guide here when building mencoder is –disable-x11 to avoid these kind of x11 issues but still I’m encountering this one. Would you have any idea why? Thanks again for the help and the great guide!
rc
Only ffmpeg is really a static build, the mencoder/mplayer is as static as it can be but still
requires some dynamic libraries.
As mencoder/mplayer does a lot of autodetecting you might simply make the X11 includes “invisible” by renaming /usr/X11/include to /usr/X11/include.1 (and do not forget to change the directory name back after a successful build.
This should stop mencoder/mplayer to find any libraries related to X11 and thus will be omitted during the compilation.
You can always check which dynamic libraries a binary by using ‘otool -L’.
In my quick test build, it looked like this:
snowy@wintermute(/Volumes/Ramdisk/mplayer) $ otool -L ./mplayer
./mplayer:
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
/System/Library/Frameworks/QuickTime.framework/Versions/A/QuickTime (compatibility version 1.0.0, current version 1756.0.0)
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 152.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0)
/System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.6.3)
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/OpenAL.framework/Versions/A/OpenAL (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/CoreAudio.framework/Versions/A/CoreAudio (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 44.0.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.42.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1038.35.0)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 38.0.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.42.0)
/System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.6.2)
Great that’s a good trick! So the output using otool means those files must reside on your system for the mencoder build to work correct? Thanks very much for the quick reply I think this issue is solved…
rc
Checking a binary with ‘otool -L’ will show you if there is a missing reference and if not, show all dynamically linked libraries for a binary.
Great thanks again!
Pingback: Quora
You could either make use of a media server such as Nullriver MediaLink or the Playstation Media Server that do transcoding on the fly.
Another approach would be to to break up the MKV container using mkvtoolnix and repackaging that into a media container that the Playstation 3 can handle using ffmpeg or mencoder, depending on what video and audio format you have in the mkv file.
Once you have a little script this should be the fastest and easiest way :)
Using Handbrake may be the easiest but not the fastest (due to the re-encoding).
hi again,
just curious using your guide is there a way to build a universal build of ffmpeg for mac or must i build on the different architectures and then lipo them together? it’s hard to find universal ready-made builds on the internet. thanks!
rc
There is no guide on how to build an universal binary since I have not written one :)
I would also try the approach of compiling ffmpeg/mplayer on different architectures and then using lipo to “glue” them together.
As some libraries want to make use of yasm you would need to check if you can disable assembler optimisations.
You could also try to compile for both architectures on one machine using the following compiler flags (ppc example on an intel box):
export CC=/usr/bin/gcc-4.0
export CFLAGS=”-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -mmacosx-version-min=10.4″
export LDFLAGS=”-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -mmacosx-version-min=10.4″
My best advice would be to first try and compile mplayer and ffmpeg as ppc binary and if that works, you can try each library if that will compile as ppc binary.
Thanks I’ll definitely look into this to see if I can figure it out!
i followed your guide intel first for ffmpeg as always the best :-) just a few comments using otool -L it shows me this:
/usr/lib/libSystem.B.dylib
only one and i suppose that’s fine? other binaries i find often show 3 or 4 when using otool -L. and i noticed if you double-click the finished binary under configuration where all the libraries are this one is not included:
libavcore
that is often included in other binaries again not quite sure what that means? but the building was just fine although i did have to follow the post from #12 about using opencore-amr project. i’ll let you know how i make out with the universal one thanks!
It should be fine although you have to check the output of ffmpeg -formats
to see if a codec you want/need is missing.
My build looks the same:
snowy@wintermute(~) $ otool -L /Users/snowy/.bin/ffmpeg
/Users/snowy/bin/ffmpeg:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
great thank you!
Hello,
bare with me this is my first big compiling project.
can’t get pass xvidcore, I’m getting (last 3 lines):
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [libxvidcore.4.dylib] Error 1
I also tried $ make && make install same result.
I can only guess what may have gone wrong.
Example compilation of xvidcore:
snowy@wintermute(/Volumes/Ramdisk) $ tar xzpf xvidcore-1.3.1.tar.gz
snowy@wintermute(/Volumes/Ramdisk) $ cd xvidcore
snowy@wintermute(/Volumes/Ramdisk/xvidcore) $ cd build/generic
snowy@wintermute(/Volumes/Ramdisk/xvidcore/build/generic) $ ./configure –prefix=/Volumes/Ramdisk
[...some configure output...]
snowy@wintermute(/Volumes/Ramdisk/xvidcore/build/generic) $ make
[..some make outout...]
/usr/bin/ranlib: file: libxvidcore.a(timer.o) has no symbols
ranlib: file: libxvidcore.a(timer.o) has no symbols
L: libxvidcore.4.dylib
—————————————————————
Xvid has been successfully built.
* Binaries are currently located in the ‘=build’ directory
* To install them on your system, you can run ‘# make install’
as root.
—————————————————————
snowy@wintermute(/Volumes/Ramdisk/xvidcore/build/generic) $ make install
D: /Volumes/Ramdisk/lib
I: /Volumes/Ramdisk/lib/libxvidcore.4.dylib
I: /Volumes/Ramdisk/lib/libxvidcore.a
D: /Volumes/Ramdisk/include
I: /Volumes/Ramdisk/include/xvid.h
Then you can delete libxvidcore.4.dylib and make ffmpeg link against the static version of xvidcore (libxvidcore.a)
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
on OSX 10.6.7
using :
$ tar xzpf xvidcore-1.3.1.tar.gz
$ cd xvidcore
$ cd build/generic
$ ./configure –prefix=/Volumes/Ramdisk
I get (last 5 lines):
A: plugins/x86_asm/plugin_ssim-a.asm
L: libxvidcore.a
ar: libxvidcore.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: libxvidcore.a: Inappropriate file type or format
make: *** [=build/libxvidcore.a] Error 1
I have to use
What version of Xcode ist installed?
Are you trying to compile an universal binary?
Please execute the following in a new shell:
$ unset CFLAGS
$ unset CXXFLAGS
$ unset LDFLAGS
$ unset CC
$ tar xzpf xvidcore-1.3.1.tar.gz
$ cd xvidcore
$ cd build/generic
$ ./configure
$ make
Does that work?
Not working, getting (last 3 lines):
ranlib: archive member: libxvidcore.a(plugin_ssim-a.o) cputype (7) does not match previous archive members cputype (16777223) (all members must match)
ranlib: for architecture: x86_64 file: libxvidcore.a(timer.o) has no symbols
make: *** [libxvidcore.a] Error 1
I’m using xcode 3.2.6 and gcc 4.2.1 on Snow 10.6.7
If you guys want an easy solution just install macports (http://www.macports.org/), and have it download ffmpeg.
The easiest solution would be to download the 64bit binary from EvalVid. :)
Can you try manually setting CFLAGS prior to running configure?
$ expot CFLAGS=”-m64″
$ export CPPFLAGS=$CFLAGS
$ tar xzpf xvidcore-1.3.1.tar.gz
$ cd xvidcore
$ cd build/generic
$ ./configure –prefix=/Volumes/Ramdisk
If that fails, in a new shell at a new location:
$ expot CFLAGS=”-m32″
$ export CPPFLAGS=$CFLAGS
$ tar xzpf xvidcore-1.3.1.tar.gz
$ cd xvidcore
$ cd build/generic
$ ./configure –prefix=/Volumes/Ramdisk
If both fail, retry both steps by adding –disable-assembly to the configure command line.
Does that help?
Forgive me for being an ignoramus. I tried to install git. I only changed the version to a newer one (1.7.4.4) and had to use a .tar.gz as the .tar.bz2 one downloaded into Terminal and froze it. So anyway, it was going well until I got an error. I would appreciate any advice as to what to do next.
(The /sw directory was created by fink, which is how I installed all the dependent files. But it only can get a pretty old version of ffmpeg)
. . . . CC xdiff/xpatience.oAR xdiff/lib.a
LINK git-daemon
ld: warning: in /sw/lib/libiconv.dylib, file was built for i386 which is not the architecture being linked (x86_64)
Undefined symbols:
"_libiconv_open", referenced from:
_reencode_string in libgit.a(utf8.o)
"_libiconv", referenced from:
_reencode_string in libgit.a(utf8.o)
"_libiconv_close", referenced from:
_reencode_string in libgit.a(utf8.o)
_reencode_string in libgit.a(utf8.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [git-daemon] Error 1
Jims-MacBook-Pro:git-1.7.4.4 jim$
You are trying to link libiconv 32bit to a 64bit binary which will not work.
There are two possible solutions:
– Build a x86_64 libiconv to link against
– Build a 32bit git binary by setting CFLAGS to -arch i386
Works for me on Leopard gcc 4.0.1. Thanks.
A few notes:
* –enable-libfaad was not supported in current ffmpeg git
* opencore-amr is required to go with –enable-libopencore-amrnb –enable-libopencore-amrwb (mentioned by previous poster too). Finding opencore source is a little obscure – via ffmpeg web site link
http://sourceforge.net/projects/opencore-amr/files/opencore-amr/
Thank you for the information! Maybe I should put up a link list of where to get all the supporting libraries.
Well it mostly works. Trying to set a size generates “illegal instruction” when running. May well be the same as this old bug. http://ffmpeg.org/pipermail/ffmpeg-devel/2006-March/015313.html
Any clues??
This really depends on how you compiled x264 and which source version you have used.
Did you try with the latest tarball from ftp://ftp.videolan.org/pub/videolan/x264/snapshots/ ?
Did you use any special compiler flags (-arch i386 versus -arch x86_64 for example)
hi again,
have you ever tried to build libfreetype? So in the ffmpeg part i passed –enable-libfreetype and i added the following build instructions prior to building ffmpeg:
$ cd ${CMPL}
$ tar xjpf ${MES}/freetype-2.4.5.tar.bz
$ cd freetype-2.4.5
$ ./configure –prefix=${TARGET} –disable-shared –enable-static
$ make -j 4 && make install
the freetype seems to build fine but i always get freetype2 not found when ffmpeg starts to build and it quits. any idea why?
rc
The ./configure script executes a subroutine called check_pkg_config to detect libfreetype2 which looks like this:
check_pkg_config(){ log check_pkg_config "$@" pkg="$1" headers="$2" funcs="$3" shift 3 $pkg_config --exists $pkg 2>/dev/null || return pkg_cflags=$($pkg_config --cflags $pkg) pkg_libs=$($pkg_config --libs $pkg) check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" && set_safe ${pkg}_cflags $pkg_cflags && set_safe ${pkg}_libs $pkg_libs }As you can see, the subroutine completely disregards any CFLAGS or LDFLAGS
you may have set and soley relies on the existence of a program/script named ‘pkg-config’
which it queries for as seen on the last line of config.log:
check_pkg_config freetype2 ft2build.h freetype/freetype.h FT_Init_FreeType
Futher information concerning pkg-config can be found here:
http://people.freedesktop.org/~dbn/pkg-config-guide.html
Anyway, for libfreetype2 to be found, a simple shell script emulation of pkg-config will do:
#!/bin/bash case $1 in --exists) exit 0 ;; --cflags) /Volumes/Ramdisk/bin/freetype-config --cflags ;; --libs) /Volumes/Ramdisk/bin/freetype-config --libs ;; esac exit 0Put that into ${TARGET}/bin prior to compiling ffmpeg and it should find freetype2 and successfully compile (and do not forget to modify the /Volumes/Ramdisk path inside the script accordingly).
Wow you’re good! :-) I’ll give it a try thanks!
Well I couldn’t get it to work maybe I’m doing something wrong. Here is a little bit of the output below when it quits in case it helps. So basically I did everything like the first time but now I made a file pkg-config.sh and placed it in ${TARGET}/bin before ffmpeg started to build. It’s a copy of what you posted only I changed the path to match my ${TARGET}. Did I do it wrong?
rmdir /Volumes/Ramdisk/sw/include/freetype2/freetype/internal
rmdir: /Volumes/Ramdisk/sw/include/freetype2/freetype/internal: No such file or directory
make: [install] Error 1 (ignored)
/usr/bin/install -c -m 644 ./builds/unix/ft2unix.h \
/Volumes/Ramdisk/sw/include/ft2build.h
/usr/bin/install -c -m 644 ./builds/unix/ftconfig.h \
/Volumes/Ramdisk/sw/include/freetype2/freetype/config/ftconfig.h
/usr/bin/install -c -m 644 /Volumes/Ramdisk/compile/freetype-2.4.5/objs/ftmodule.h \
/Volumes/Ramdisk/sw/include/freetype2/freetype/config/ftmodule.h
/usr/bin/install -c -m 755 ./builds/unix/freetype-config \
/Volumes/Ramdisk/sw/bin/freetype-config
/usr/bin/install -c -m 644 ./builds/unix/freetype2.m4 \
/Volumes/Ramdisk/sw/share/aclocal/freetype2.m4
/usr/bin/install -c -m 644 ./builds/unix/freetype2.pc \
/Volumes/Ramdisk/sw/lib/pkgconfig/freetype2.pc
ERROR: freetype2 not found
If you think configure made a mistake, make sure you are using the latest
version from Git. If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file “config.log” produced by configure as this will help
solving the problem.
logout
[Process completed]
The script must be called ‘pkg-config’ not ‘pkg-config.sh’.
Also, make it executable by ‘chmod 755 pkg-config’
Hi hexeract,
I met troubles when compiling ffmpeg.
When I add the –enable-libopencv flag, configure give the error message: opencv not found.
I installed opencv, and have tried opencv-2.0, opencv-2.1, opencv-2.2, opencv-2.3, the result is the same.
could you give some suggestions?
Thanks.
The problem of ffmpeg not finding opencv has two reasons: It gnores CFLAGS and LDFLAGS concerning the check for opencv and uses pkg-config to obtain opencv specific compiler and linker flags.
Diving deep into the configure script for ffmpeg reveal two shell functions responsible for checking the availablity of opencv.
Within the configure script, it uses require-pkg_config to detect and (if found, set the CFLAGS and LDFLAGS accordingly).
Actual configure line checking for opencv:
require_pkg_config:
require_pkg_config(){ pkg="$1" check_pkg_config "$@" || die "ERROR: $pkg not found" add_cflags $(get_safe ${pkg}_cflags) add_extralibs $(get_safe ${pkg}_libs) }check_pkg_config which is called by require_pkg_config
check_pkg_config(){ log check_pkg_config "$@" pkg="$1" headers="$2" funcs="$3" shift 3 $pkg_config --exists $pkg 2>/dev/null || return pkg_cflags=$($pkg_config --cflags $pkg) pkg_libs=$($pkg_config --libs $pkg) check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" && set_safe ${pkg}_cflags $pkg_cflags && set_safe ${pkg}_libs $pkg_libs }Be sure to create a 2GB sized Ramdisk :)
The first step is to create a file in ${TARGET}/bin called ‘pkg-config’. Do not forget to change the path if you have named your ramdisk differently.
#!/bin/bash case $1 in --exists) exit 0 ;; --cflags) echo "-I/Volumes/Ramdisk/include -I/Volumes/Ramdisk/include/opencv" ;; --libs) echo "-L/Volumes/Ramdisk/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann" ;; esacIn order to build opencv the ‘cmake’ program is required, so we need to build it.
Building opencv
Building ffmpeg
Sadly, this will blow up, checking the config.log shows:
Undefined symbols for architecture i386: "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from: cv::OutOfMemoryError(unsigned long)in libopencv_core.a(alloc.o) _cvSetMemoryManager in libopencv_core.a(alloc.o) _cvSetIPLAllocators in libopencv_core.a(array.o) _cvReleaseMat in libopencv_core.a(array.o) _cvInitMatHeader in libopencv_core.a(array.o) _cvCreateMatHeader in libopencv_core.a(array.o) _cvInitMatNDHeader in libopencv_core.a(array.o)When researching the error message it seems that additional linking to libstdc++ is required. A minor change to pkg-config is required to make the configure run of ffmpeg to be successful:
#!/bin/bash case $1 in --exists) exit 0 ;; --cflags) echo "-I/Volumes/Ramdisk/include -I/Volumes/Ramdisk/include/opencv" ;; --libs) echo "-lstdc++ -L/Volumes/Ramdisk/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann" ;; esac exit 0With this modification, the ffmpeg ./configure run works fine and ffmpeg builds:
/Volumes/Ramdisk/bin/ffmpeg ffmpeg version N-31743-g324b8ad, Copyright (c) 2000-2011 the FFmpeg developers built on Aug 3 2011 19:22:19 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3) configuration: --prefix=/Volumes/Ramdisk --enable-libopencv --enable-static --disable-shared --disable-yasm libavutil 51. 11. 1 / 51. 11. 1 libavcodec 53. 9. 1 / 53. 9. 1 libavformat 53. 6. 0 / 53. 6. 0 libavdevice 53. 2. 0 / 53. 2. 0 libavfilter 2. 27. 5 / 2. 27. 5 libswscale 2. 0. 0 / 2. 0. 0 Hyper fast Audio and Video encoder usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}... Use -h to get full help or, even better, run 'man ffmpeg'I am not sure how to use opencv via ffmpeg but I hope you can retrace my steps successfully to compile ffmpeg linking against opencv.
It works. Thank you very much! I have another question. When I use frei0r filter like this
ffmpeg -i 123.avi -vf “frei0r=distort0r:0.5:0.01″ /Volumes/123.mp4
ffmpeg gives the following error message
[frei0r @ 0x16029a0] Could not find module ‘distort0r’
Error initializing filter ‘frei0r’ with args ‘distort0r:0.5:0.01′
I have no idea about this, please help me.
Thanks again.
Thank you!
Checking the libavfilter documentation, section 8.12:
To enable compilation of this filter you need to install the frei0r header and configure FFmpeg with –enable-frei0r.
I assume you need compile frei0r and then compile ffmpeg accordingly.
If you already have ffmpeg compiled with (a recent version of) frei0r the only advice I can give you is to ask on the ffmpeg user mailing list for assistance.
I got it thanks! :-)
Hi Hexeract,
I have been following your post several weeks and I’ve got to make a Bash Script to automate de process of compiling FFmpeg in Mac OS X 10.6 (Snow Leopard) with the following tools:
- Git
- Mercurial
- Nasm
- Yasm
- Lame
- FAAD2
- FAAC
- Libvpx (WebM – VP8)
- OpenCore-AMR
- SDL
- x264
- FFmpeg
I am missing (Theora, Vorbis, Xvid…) those will come later.
I have been doing some research and I am been unable to make a static link. otool -L shows me:
otool -L /usr/local/bin/ffmpeg
/usr/local/bin/ffmpeg:
/System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 38.0.0)
/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 152.0.0)
/System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
/usr/local/lib/libopencore-amrwb.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/lib/libopencore-amrnb.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/lib/libmp3lame.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/lib/libfaac.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
/usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 44.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.43.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.62.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1038.36.0)
Any ideas? I am up to sharing the bash script and credit with you.
Thanks in advance.
For what its worth – I started a bash script in 2009 when this thread first started and I am happy to share it with you in case you can use it. I haven’t run it in a while, but if I remember correctly it worked at the time to automate the process. It is a menu driven script. Obviously the sources may have changed and other intricacies may have changed but maybe it can help you get a start. You can download my bash script here: http://cl.ly/1A3N3d3A1G3d132V1g2h
Thank you very much for sharing your script!
I already have a set of shell scripts to automatically build ffmpeg, ffmpeg-libav and mplayer but they are crude and should never see the light of day :)
If you are interested please contact me again and I will send them via email to you (or any other interested party).
Great! I definitelly will take a look at it. I’ll probably have to make many changes to mine before it sees the light as Hexeract says :P…
I’ll take some time tonight (8 pm here now) and will get back to you tomorrow with some feedback.
Many thanks in advance!!!!!
Any chance any of the scripts available supports binaries that work all the way back to Tiger as well as PPC? I’d like to build a super-fat ffmpeg binary that works on basically every Mac system still in use. There is a lame binary available online that is built like that, but no ffmpeg binary like that as far as I’ve seen.
Basically, the best approach would be to build each architecture seperatly and then “glueing” them together using ‘lipo’.
To create PPC binaries you need Xcode 3 and the following environment setup:
export CC=/usr/bin/gcc-4.0
export CFLAGS=”-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -mmacosx-version-min=10.4″
export LDFLAGS=”-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -mmacosx-version-min=10.4″
Trying to use multiple ‘-arch’ arguments will just break compilation for some media libraries.
I remember I once tried to do that but it was quite a lot of hassle to do it on an Intel machine
and as I did not need a PPC binary I let it be.
If you do have a PPC machine it would be interesting to know if my guide helps in compiling a PPC only version (since that would be built by default).
Note – click the DIRECT LINK in the upper right corner to DOWNLOAD the script.
I already have a bash script :)
Actually, I have 4. One for each program and a script that compiles all the media codec libraries.
Judging from your ‘otool -L’ output, I suspect quite a few of those come from the SDL you include.
Why would you want to include SDL on MacOSX?
Concerning OpenCore AMR:
I used the following source archive: vo-amrwbenc-0.1.1.tar.gz
Simply unpacking and compiling it:
$ tar xzpf vo-amrwbenc-0.1.1.tar.gz
$ cd vo-amrwbenc-0.1.1
$ ./configure –prefix=/Volumes/Ramdisk –enable-static –disable-shared
Provides libraries that can be statically linked to ffmpeg.
The path shown in the output of ‘otool -L’ is ‘/usr/local/lib’
I would think you compiled it without –disable-shared and the target was /usr/local/.
In any case I do not recommend compiling to /usr/local/ but to a ram disk instead.
It will keep your system clean and you do not need to worry about breaking things.
This is what my output looks like:
snowy@wintermute(~) $ ffmpeg -version
ffmpeg version N-32911-gbf85b90-snowy, Copyright (c) 2000-2011 the FFmpeg developers
built on Sep 25 2011 10:28:48 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3)
configuration: –prefix=/Volumes/ffmpeg-latest/ –as=yasm –extra-version=snowy –disable-shared –enable-static –disable-ffplay –disable-ffserver –enable-gpl –enable-pthreads –enable-gray –enable-postproc –enable-libfaac –enable-libmp3lame –enable-libtheora –enable-libvorbis –enable-libx264 –enable-libxvid –enable-libspeex –enable-bzlib –enable-zlib –enable-libopencore-amrnb –enable-libopencore-amrwb –enable-libxavs –enable-libvo-aacenc –enable-libvo-amrwbenc –enable-nonfree –enable-version3 –enable-runtime-cpudetect
libavutil 51. 17. 0 / 51. 17. 0
libavcodec 53. 17. 0 / 53. 17. 0
libavformat 53. 13. 0 / 53. 13. 0
libavdevice 53. 4. 0 / 53. 4. 0
libavfilter 2. 43. 5 / 2. 43. 5
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 51. 2. 0 / 51. 2. 0
ffmpeg N-32911-gbf85b90-snowy
libavutil 51. 17. 0 / 51. 17. 0
libavcodec 53. 17. 0 / 53. 17. 0
libavformat 53. 13. 0 / 53. 13. 0
libavdevice 53. 4. 0 / 53. 4. 0
libavfilter 2. 43. 5 / 2. 43. 5
libswscale 2. 1. 0 / 2. 1. 0
libpostproc 51. 2. 0 / 51. 2. 0
snowy@wintermute(~) $ otool -L .bin/ffmpeg
.bin/ffmpeg:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
WoW … That’s exactly what I need … :)
I’ll follow your advice and will get back tomorrow with feedback.
Thank you very much.
JUST GREAT!!!
I have been able to make a better binary (more library independent) than mine thanks to your recommendations. Making the Ramdisk just made my day!!!!
Thank you very much.
I have a question. Why do you compile section “Building libav’s ffmpeg” after FFmpeg? Aren’t the libs into FFmpeg git repository? If they are needed to be compiled, shouldn’t it be done before building FFmpeg?
Thanks in advance.
I may have been unclear in the guide :( I will fix that.
I do not build libav’s ffmpeg _after_ ffmpeg. I build either of the three after all “base libraries” have been successfully compiled.
Most likely building libav’s ffmpeg after ffmpeg will work and will not introduce any unwanted dependencies.
It was not your fault …. I guess it was too late and I needed some rest when I wrote that comment :)
Thank you very much!!!
You are welcome. If you require further assistance, do not hesitate to ask.
It would be great to put this up on gist.github.com as a living document
You are welcome to publish the blog posting on gist.github.com.
If you do, please make a reference to the original source.
Also, I do update the blog posting when a new version of a library is available or configure flags change.
I would like to compile FFmpeg with freetype and libass. Any help for this is welcome !
TIA
What have you tried so far and what went wrong?
Well, two issues. I cannot get the Freetype to compile correctly (I think). And compiling libass gives this error:
“checking for FREETYPE… configure: error: in `/Volumes/tempdisk/compile/libass-0.10.0′:
configure: error: The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.
Alternatively, you may set the environment variables FREETYPE_CFLAGS
and FREETYPE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
To get pkg-config, see .
See `config.log’ for more details.”
It would be great if you figure out how to compile both because with 0.90 it should be (finally) possible to hardcode subtitles.
I am a bit of a noob with compiling though following your steps I manage to do it every time. As said, I am a bit of a noob to try it with freetype and libass :-) :-)
That is easy to solve. Create a “fake” pkg-config script. Please check the other comments of this posting where I describe on how to build the pkg-config script for freetype2 (once freetype2 was successfully compiled and installed into the Ramdisk).
libass actually has quite a few dependencies and a bad configure script since it will state it has found other dependencies which clearly are not available:
– enca
– fontconfig
– fribidi
Once you compile freetype2, enca, fontconfig and fribidi the compilation of libass will fail
since some types will not match… I am not enough of a programmer to fix this and I have not yet found enough information about how others managed to fix it. I would suspect not using the latest fribidi might help but this assumption is untested…
Anyone successfully got FFmpeg build with the libass encoders?
As stated previously, compiling libass itself is not the problem, the dependencies are and I stopped at “fribidi”. If you do manage to take the time and find out which version will actually work with libass, please let me know…
It would be great some-one could manage to compile FFmpeg with LibASS support. Reading above it doesn’t seems to be easy.
It must be possible since both Handbrake and VLC have libass support (as far as I know). If only there was access to their build infrastructure/scripts…
The latter would probably show which versions have to be used and will play nicely together to get a (static) libass library…
If anyone does have any helpful suggestions/hints, please do not hesitate to make a comment on this blog or contact me.
Pingback: Compiling FFmpeg/MPlayer with single command | Video Gorillas
This site seems to have a way to compile FFmpeg with libass. http://ffmpeg.zeranoe.com/builds/
Unfortunality only for Windows. Maybe you dig into this an try it for OS X?
Also take a look at this page : https://ffmpeg.org/trac/ffmpeg/wiki/MacOSXCompilationGuide
Maybe it can help too.
That guide is not really of any help, finding the libraries can be a hassle but is not too difficult.
Mentioning that freetype is needed is merely a hint, but does not mention of the other dependencies libass actually has…
The guide provides an overview of what can be included but has no step to step compilation documentation.
There must be a working set of versions of freetype, enca, frontconfig and fribidi for libass to compile (since it obviously has been done for VLC and the win32 static ffmpeg binary that is mentioned in the URL you have provided) but it seems everyone is keeping it secret on how to actually build libass. Even the libass author fails to document on how to build libass… go figure..
Sadly, the site you mention does not provide exact versions for the libass dependencies (and even fails to mention there are any!), so I am back to square one.
Nevertheless, if I have some spare time at the weekend I will give it another (most likely futile) try.
It seems it is needed to install pkg-config – but I cannot get that part working too.
the pkg-config part is easy, I assume you need that for freetype to be found?
Please search the comments where I have described on how to set up a “dummy” pkg-config.
If you need a different pkg-config modify accordingly.
All that pkg-config does is to supply the include path and library path and the configure picks up on the result.
Hi,
I know this is not exactly ffmpeg, but do you know how to build dvdauthor on Mac? I keep getting an error that I need libpng(-devel) but I haven’t been able to figure it out. Thought it won’t hurt to ask. :-)
The program dvdauthor was not written with libpng 1.5.x in mind which has changed some internals thus breaking a source code line in ./src/spuunmux.c. Also, in the same file, the reference for the zlib.h include file is missing. The two perl lines fixes the problems in a very crude fashion.
On my box MacOSX 10.7.3, latest Xcode and installed command line tools via Xcode, the following script works and results in a dvdauthor binary:
#!/bin/bash NAME=Ramdisk SIZE=2097152 DISK_ID=$(hdid -nomount ram://$SIZE) newfs_hfs -v ${NAME} ${DISK_ID} diskutil mount ${DISK_ID} export CC=clang cd /Volumes/Ramdisk/ BASEDIR=$(pwd) mkdir $BASEDIR/sw mkdir $BASEDIR/sources cd $BASEDIR/sources export LDFLAGS="-L$BASEDIR/sw/lib" export CFLAGS="-I$BASEDIR/sw/include" curl -O http://zlib.net/zlib-1.2.6.tar.gz tar xzpf zlib* cd zlib* ./configure --prefix=$BASEDIR/sw --static make && make install cd $BASEDIR/sources curl -O http://dfn.dl.sourceforge.net/project/libpng/libpng15/1.5.10/libpng-1.5.10.tar.gz tar xzpf libpng* cd libpng* ./configure --prefix=$BASEDIR/sw --enable-static --disable-shared make && make install cd $BASEDIR/sources curl -O http://garr.dl.sourceforge.net/project/dvdauthor/dvdauthor/0.7.0/dvdauthor-0.7.0.tar.gz tar xzpf dvdauthor* cd dvdauthor* FIXME=./src/spuunmux.c perl -p -i -e "s;<png.h>;<png.h>\n#include <zlib.h>\n" $FIXME perl -p -i -e "s;png_ptr->jmpbuf;png_jmpbuf(png_ptr);" $FIXME ./configure --prefix=$BASEDIR/sw make && make install clear cd $BASEDIR/sw/bin ls -l dvdauthor ./dvdauthor -version otool -L ./dvdauthorHope this helps.
As always you’re the best! :-) Thanks for the help. Just curious this is a static build right? I used your script on 10.7.3 (worked perfectly) and with otool -L I got this:
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.3.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
/usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 46.1.0)
But on an older Mac with Xcode 3 I removed the exportCC=clang line and got this:
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libxml2.2.dylib (compatibility version 9.0.0, current version 9.16.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.7)
/usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 36.0.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
Anything to be concerned about you think? Some older dvdauthor binaries I found on the internet even show different results so I’m not sure? Thanks again!
That looks about right. You can never really build a “truly” static binary on MacOSX,
you will always end up with at least libSystem*dylib…
What you can do is to avoid too many “outside” dependencies and have the binary just depend on the (minima) set of system libraries provided by the operating system.
This is my otool -L output:
./dvdauthor:
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.3.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
/usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 46.1.0)
That binary should be able to run on any other 10.7.x System. If you target an older operating system you will probably have to use the gcc provided by Xcode 3,x and use the following environment variables for CC, CFLAGS and LDFLAGS, which you can place right after setting LDFLAGS and CFLAGS in the script:
export CC=”/Developer-old/usr/bin/gcc-4.0″
export CFLAGS=”$CFLAGS -isysroot /Developer-old/SDKs/MacOSX10.4u.sdk -arch i386 -mmacosx-version-min=10.4″
export LDFLAGS=”$LDFLAGS -Wl,-syslibroot,/Developer-old/SDKs/MacOSX10.4u.sdk -arch i386 -mmacosx-version-min=10.4″
This will produce the following file:
otool -L:
./dvdauthor:
/usr/lib/libiconv.2.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/lib/libxml2.2.dylib (compatibility version 9.0.0, current version 9.16.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.11)
/usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 32.0.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
file /Volumes/Ramdisk/sw/bin/dvdauthor:
/Volumes/Ramdisk/sw/bin/dvdauthor: Mach-O executable i386
As I do not have access to a 10.4 machine I can not verify that this binary will actually run.
Ok since I get the same I should be ok. Thanks again! :-)
Any luck with FFmpeg and Libass? ;)
I have not had any spare time to play around with that problem. Also, as I do not need that functionality myself, the priority for this is very low.
You can try yourself, it is just a matter of trying various combinations of the required dependencies until libass compiles, from there on, compiling ffmpeg should not be a problem..