现在的位置: 首页 > 综合 > 正文

Compiling 64-bit FFmpeg on Mac OS X Lion or Snow Leopard

2017年11月26日 ⁄ 综合 ⁄ 共 6412字 ⁄ 字号 评论关闭

(updated September 26, 2011)

FFmpeg (http://www.ffmpeg.org) is open source software to record, convert and stream audio and video in numerous formats.

The FFmpeg package requires the following external libraries, which are to be downloaded separately:

  • LAME (Lame Aint an MP3 Encoder), a high quality MPEG Audio Layer III (MP3) encoder
  • FAAC/FAAD2 (Freeware Advanced Audio Coder and Decoder 2), an implementation of the AAC audio compression format.
  • SDL (Simple DirectMedia Layer), is a multimedia library that provides access to graphics, sound, and input devices via OpenGL, and the 2D-video framebuffer.

A successful FFmpeg build yields the following components:

  • FFmpeg libraries, the most important being libavcodec that contains all the FFmpeg audio/video encoders and decoders.
  • ffmpeg, the main command line tool to convert one video file type to another.
  • ffserver, an HTTP a RSTP (Real Time Streaming Protocol) multimedia streaming server.
  • ffplay, a simple media player based on SDL and on the FFmpeg libraries.

Installation steps

1) First, download and install Xcode 3.2.1 (Snow Leopard) or  Xcode 4.1 (Lion) development environment from Apple (https://developer.apple.com/xcode/). Because all sources for FFmpeg are written in C, the gcc compiler that comes with Xcode must be available
in your Terminal shell, the command:

$ gcc --version

should print something like:

i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

2) Download the latest LAME sources from http://sourceforge.net/projects/lame/files/

Unpack, configure, build, and install:

$ tar zxvf lame-398-2.tar.gz
$ cd lame-398-2
$ ./configure
$ make
$ sudo make install

3) Download the latest sources of both FAAC and FAAD2 from http://sourceforge.net/projects/faac/files/

Unpack, configure, build, and install them both:

$ tar zxvf faac-1.28.tar.gz
$ cd faac-1.28
$ ./configure
$ make
$ sudo make install
$
$ tar zxvf faad2-2.7.tar.gz
$ cd faad2-2.7
$ ./configure
$ make
$ sudo make install

4) Download the stable source code of SDL at http://www.libsdl.org/download-1.2.php

Then, generate configuration script, configure, build, and install:

$ cd SDL-1.2.14
$ ./autogen.sh
$ ./configure --disable-assembly
$ make
$ sudo make install

5). Finally, get the latest sources from the FFmpeg project, configure, build, and install:

$ svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
$ cd ffmpeg
$ ./configure --enable-libmp3lame --enable-libfaac --enable-libfaad --enable-gpl --enable-nonfree --enable-shared --disable-mmx --arch=x86_64 --cpu=core2
$ make
$ sudo make install

If all goes well, the libraries will be installed in /usr/local/lib, and the executables ffmpeg, ffserver and ffplay in /usr/local/bin

Enjoy FFmpeg!

Optional installs

This article would not be complete without optional tools and codecs you may install. They are suited for people who are willing to experiment with compiling and installing stuff. I will keep adding items to this section after I have successfully implemented
them myself.

First, we’ll install some extra tools that are required for some of the compiles, or will make your installations easier.

FLVtool

You may have noticed that Flash Video (.flv) files produced by FFmpeg may not show their running time correctly in a media player. FLVtool can insert meta data (e.g. running length) into .flv files. For more information, see http://rubyforge.org/projects/flvtool2/

Because Snow Leopard and Lion both have RubyGems (a Ruby package manager) pre-installed, flvtool2 can be easily obtained:

$ sudo gem install flvtool2

NASM and Yasm

Snow Leopard comes with an old version of NASM (The Netwide Assembler). Both Snow Leopard and Lion have no Yasm (Yet Another Assembler) installed. Therefore, get the latest stable release of NASM at http://www.nasm.us/pub/nasm/releasebuilds/ and of Yasm at
http://www.tortall.net/projects/yasm/releases/, install both assemblers:

$ tar zxvf nasm-2.0.7.tar.bz2
$ ./configure
$ make
$ sudo make install
$
$ tar zxvf yasm-0.8.0.tar.gz
$ ./configure
$ make
$ sudo make install

Git

Both Subversion (svn) and CVS are pre-installed on Snow Leopard, but you may also want the other popular version control system, Git. To install Git on Snow Leopard (under Lion it is already present in your developer environment) follow the instructions at

http://www.crainbandy.com/how-to/how-to-install-git-on-mac-os-x-leopard-snow-leopard

H.264

x264 is a free software library for encoding video streams into the H.264/MPEG-4 AVC format.

Yasm (installed earlier) is required to compile several assembly language routines present in the x264 code.

To obtain the x264 sources, either download the daily snapshot from http://download.videolan.org/pub/videolan/x264/snapshots/, or use Git:

$ git clone git://git.videolan.org/x264.git
$ cd x264

Take care that the version of x264 >= 0.78. Then, configure, build and install the x264 library with:

$ ./configure
$ make
$ sudo make install

To rebuild FFmpeg to include H.264 support, add these two directives to the configure command:

--enable-libx264 --enable-static

Optional other formats

  • XviD format: libxvid, http://downloads.xvid.org/downloads/xvid_latest.tar.gz
  • Ogg format: libogg, http://downloads.xiph.org/releases/ogg/
  • Ogg Vorbis audio: libvorbis, http://downloads.xiph.org/releases/vorbis/ (requires Ogg)
  • AMR-NarrowBand audio: libamr-nb, http://www.penguin.cz/~utx/amr
  • AMR-WideBand audio: libamr-wb, http://www.penguin.cz/~utx/amr
  • Theora video: libtheora, svn co http://svn.xiph.org/trunk/theora theora (requires Ogg and Vorbis)
  • Speex audio: libspeex, git clone git://git.xiph.org/speex.git (requires Ogg)
  • FLAC audio: libflac, http://sourceforge.net/projects/flac/files/flac-src/
  • GSM audio: libgsm, http://user.cs.tu-berlin.de/~jutta/gsm/gsm-1.0.13.tar.gz
  • NUT format: libnut, svn co svn://svn.mplayerhq.hu/nut/src/trunk/ nut
  • Schroedinger video: libschroedinger, http://diracvideo.org/download/schroedinger/ (requires liboil, http://liboil.freedesktop.org/download/)

Usage examples

  • Extract specific images at a set time, e.g. grabbing 10 frames, 1 per second, starting at 5 minutes:

    ffmpeg -i video.avi -ss 300 -r 1 -t 10 image%02d.png
  • Create a movie out of numbered image files:

    ffmpeg -f image2 -i image%d.jpg video.mpg
  • Converting any video to DVD-compatible MPEG2:

    ffmpeg -y -i video.xyz -vcodec mpeg2video -target ntsc-dvd -r ntsc -deinterlace -aspect 4:3 outputfile.m2v
  • Convert an AVI to a standard PAL DVD

    ffmpeg -i video.avi -target pal-dvd -ps 4000000000 -aspect 16:9 video.mpeg
  • Convert MOV to AVI:

    ffmpeg -i video.mov -sameq -vcodec msmpeg4v2 -acodec pcm_u8 -s 640×360 video.avi
  • Convert FLV to SWF:

    ffmpeg -i video.flv -acodec copy -vcodec copy video.swf
  • Extract audio from an AVI:

    ffmpeg -i video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 audio.mp3
  • Convert MTS/M2TS (AVCHD) to AVI:

    ffmpeg -i video.mts -vcodec libxvid -b 18000k -acodec ac3 -deinterlace -s 1440×1080 video.avi
  • Convert MP4 to 3GP (mobile) format

    ffmpeg -i input_video.mp4 -s 176×144 -vcodec h263 -r 25 -b 12200 -ab 12200 -ac 1 -ar 8000 video.3gp
  • Concatenate two AVI’s:

    ffmpeg -i video1.avi -sameq intermediate1.mpg

    ffmpeg -i video2.avi -sameq intermediate2.mpg

    cat intermediate1.mpg intermediate2.mpg > intermediate.mpg

    ffmpeg -i intermediate.mpg -sameq video.avi

抱歉!评论已关闭.