iOS 开发音视频流[1]---FFmpeg

原文地址: http://www.jianshu.com/p/4811f11aed27

本文是自己实际开发过程中遇到的问题。

1、准备

1.1、Xcode

`XCode`提供了Mac平台开发环境必须的gcc编译器,要注意的是`XCode` 安装后并没有命令行的gcc可用,
还需要打开`XCode`,在某个设置里添加Command Line Tools,`XCode`就会自动下载并安装好gcc,
同时还有git也被安装了。

1.2、Homebrew

`homebre` 是 Mac 平台上的一个包管理工具,提供了许多 Mac 下没有的 Linux工具等,
而且安装工具极其简单,一句命令行 gameOver。

2、安装FFmpeg

ffmpeg的官方网站是:http://ffmpeg.org/ 

2.1、在终端输入以下命令行:

zhuyuhui-4:~ zhuyuhui$ brew install ffmpeg
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
bchunk              elasticsearch@5.6   kibana@5.6          logstash@5.6
==> Updated Formulae
apibuilder-cli      grafana             mercurial           sassc
arangodb            grakn               metricbeat          scons
azure-cli           grpc                mighttpd2           shpotify
bitrise             harfbuzz            mosh                sonarqube
citus               heartbeat           nickle              streamlink
commandbox          influxdb            open-scene-graph    supersonic
couchdb             itstool             opencoarrays        swift-protobuf
cppad               jfrog-cli-go        opusfile            terragrunt
crystal-icr         kibana              paket               traefik
dbus                kotlin              pgrouting           upscaledb
elasticsearch       libfaketime         planck              urh
faac                libopusenc          poco                vault
faas-cli            libphonenumber      pqiv                xtensor
filebeat            libtrace            protobuf            youtube-dl
fn                  lighttpd            protobuf-c          zbackup
folly               logstash            protobuf-swift      zenity
git-cinnabar        lxc                 pumba               zimg
gjstest             mariadb@10.1        purescript

Error: Your Xcode (8.3.3) is too outdated.
Please update to Xcode 9.1 (or delete it).
Xcode can be updated from the App Store.

zhuyuhui-4:~ zhuyuhui$ 

我的电脑上同时安装了Xcode8.3.3和Xcode9.0.1[两个Xcode都安装在Applications]。出现上述错误,找到解决方法如下:

https://stackoverflow.com/questions/40296756/homebrew-saying-xcode-is-outdated

So as @NicolasMiari mentioned in a comment above, the fix to my issue ended up having to 
have both Xcode 7 and Xcode 8 on my machine. I went on the apple developer site, downloaded Xcode 8,
saved it to my documents and then used: sudo xcode
-select -switch ~/Documents/Xcode.app/ and then ran my brew install which worked as expected. Afterwards I ran: sudo xcode-select -switch /Applications/Xcode.app/ to switch back to Xcode 7.3.1. Hope this helps someone else! and thanks for the suggestions!

 

按照上述方法,先执行

sudo xcode-select -switch /Applications/Xcode9.app/

然后执行下面代码:

Last login: Thu Nov 16 09:11:31 on console
zhuyuhui-4:~ zhuyuhui$ brew install ffmpeg
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
bchunk              elasticsearch@5.6   kibana@5.6          logstash@5.6
==> Updated Formulae
apibuilder-cli      grafana             mercurial           sassc
arangodb            grakn               metricbeat          scons
azure-cli           grpc                mighttpd2           shpotify
bitrise             harfbuzz            mosh                sonarqube
citus               heartbeat           nickle              streamlink
commandbox          influxdb            open-scene-graph    supersonic
couchdb             itstool             opencoarrays        swift-protobuf
cppad               jfrog-cli-go        opusfile            terragrunt
crystal-icr         kibana              paket               traefik
dbus                kotlin              pgrouting           upscaledb
elasticsearch       libfaketime         planck              urh
faac                libopusenc          poco                vault
faas-cli            libphonenumber      pqiv                xtensor
filebeat            libtrace            protobuf            youtube-dl
fn                  lighttpd            protobuf-c          zbackup
folly               logstash            protobuf-swift      zenity
git-cinnabar        lxc                 pumba               zimg
gjstest             mariadb@10.1        purescript

Error: Your Xcode (8.3.3) is too outdated.
Please update to Xcode 9.1 (or delete it).
Xcode can be updated from the App Store.

zhuyuhui-4:~ zhuyuhui$ brew install ffmpeg
Updating Homebrew...
==> Installing dependencies for ffmpeg: lame, x264, xvid
==> Installing ffmpeg dependency: lame
==> Downloading https://homebrew.bintray.com/bottles/lame-3.99.5.high_sierra.bot
######################################################################## 100.0%
==> Pouring lame-3.99.5.high_sierra.bottle.1.tar.gz
🍺  /usr/local/Cellar/lame/3.99.5: 27 files, 2MB
==> Installing ffmpeg dependency: x264
==> Downloading https://homebrew.bintray.com/bottles/x264-r2795.high_sierra.bott
######################################################################## 100.0%
==> Pouring x264-r2795.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/x264/r2795: 11 files, 3.2MB
==> Installing ffmpeg dependency: xvid
==> Downloading https://homebrew.bintray.com/bottles/xvid-1.3.4.high_sierra.bott
######################################################################## 100.0%
==> Pouring xvid-1.3.4.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/xvid/1.3.4: 10 files, 1.2MB
==> Installing ffmpeg
==> Downloading https://homebrew.bintray.com/bottles/ffmpeg-3.4.high_sierra.bott
######################################################################## 100.0%
==> Pouring ffmpeg-3.4.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/ffmpeg/3.4: 248 files, 50.9MB
zhuyuhui-4:~ zhuyuhui$ 

紧接着我们执行 

brew info ffmpeg

zhuyuhui-4:~ zhuyuhui$ brew ls
ffmpeg        node        python        ssh-copy-id    yasm
flow        nvm        python3        watchman
gdbm        openssl        readline    x264
lame        pcre        ruby        xvid
libyaml        pkg-config    sqlite        xz
zhuyuhui-4:~ zhuyuhui$ brew info ffmpeg
ffmpeg: stable 3.4 (bottled), HEAD
Play, record, convert, and stream audio and video
https://ffmpeg.org/
/usr/local/Cellar/ffmpeg/3.4 (248 files, 50.9MB) *
  Poured from bottle on 2017-11-16 at 10:47:38
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/ffmpeg.rb
==> Dependencies
Build: nasm ✘, pkg-config ✔, texi2html ✘
Recommended: lame ✔, x264 ✔, xvid ✔
Optional: chromaprint ✘, fdk-aac ✘, fontconfig ✘, freetype ✘, frei0r ✘, game-music-emu ✘, libass ✘, libbluray ✘, libbs2b ✘, libcaca ✘, libgsm ✘, libmodplug ✘, libsoxr ✘, libssh ✘, libvidstab ✘, libvorbis ✘, libvpx ✘, opencore-amr ✘, openh264 ✘, openjpeg ✘, openssl ✘, opus ✘, rtmpdump ✘, rubberband ✘, sdl2 ✘, snappy ✘, speex ✘, tesseract ✘, theora ✘, two-lame ✘, wavpack ✘, webp ✘, x265 ✘, xz ✔, zeromq ✘, zimg ✘
==> Options
--with-chromaprint
    Enable the Chromaprint audio fingerprinting library
--with-fdk-aac
    Enable the Fraunhofer FDK AAC library
--with-fontconfig
    Build with fontconfig support
--with-freetype
    Build with freetype support
--with-frei0r
    Build with frei0r support
--with-game-music-emu
    Build with game-music-emu support
--with-libass
    Enable ASS/SSA subtitle format
--with-libbluray
    Build with libbluray support
--with-libbs2b
    Build with libbs2b support
--with-libcaca
    Build with libcaca support
--with-libgsm
    Build with libgsm support
--with-libmodplug
    Build with libmodplug support
--with-libsoxr
    Enable the soxr resample library
--with-libssh
    Enable SFTP protocol via libssh
--with-libvidstab
    Enable vid.stab support for video stabilization
--with-libvorbis
    Build with libvorbis support
--with-libvpx
    Build with libvpx support
--with-opencore-amr
    Enable Opencore AMR NR/WB audio format
--with-openh264
    Enable OpenH264 library
--with-openjpeg
    Enable JPEG 2000 image format
--with-openssl
    Enable SSL support
--with-opus
    Build with opus support
--with-rtmpdump
    Enable RTMP protocol
--with-rubberband
    Enable rubberband library
--with-sdl2
    Enable FFplay media player
--with-snappy
    Enable Snappy library
--with-speex
    Build with speex support
--with-tesseract
    Enable the tesseract OCR engine
--with-theora
    Build with theora support
--with-tools
    Enable additional FFmpeg tools
--with-two-lame
    Build with two-lame support
--with-wavpack
    Build with wavpack support
--with-webp
    Enable using libwebp to encode WEBP images
--with-x265
    Enable x265 encoder
--with-xz
    Enable decoding of LZMA-compressed TIFF files
--with-zeromq
    Enable using libzeromq to receive commands sent through a libzeromq client
--with-zimg
    Enable z.lib zimg library
--without-gpl
    Disable building GPL licensed parts of FFmpeg
--without-lame
    Disable MP3 encoder
--without-qtkit
    Disable deprecated QuickTime framework
--without-securetransport
    Disable use of SecureTransport
--without-x264
    Disable H.264 encoder
--without-xvid
    Disable Xvid MPEG-4 video encoder
--HEAD
    Install HEAD version
zhuyuhui-4:~ zhuyuhui$ 

Game Over 安装完毕。
注意:我们之前执行 sudo xcode-select -switch /Applications/Xcode9.app/ 之后才安装FFmpeg成功,如果你之后还需要使用Xcode8.3.3,那么最好再执行 sudo xcode-select -switch /Applications/Xcode.app/

下面是我应用程序里Xcode截图:

 

 

 

posted @ 2017-11-16 10:35  yuhui.Mr  阅读(1032)  评论(0编辑  收藏  举报