在Mac OSX上安装ffmpeg && ffmpeg命令行将h264封装为mp4

ffmpeg功能强大,可以通过命令行来对音视频进行处理。为了使用其功能,我在Mac上对其进行了安装。

我的Mac OS X 系统版本:OS X Yosemite, 10.10.14

关于ffmpeg在Mac OS X上的编译,FFmpeg上有官方文档说明:https://trac.ffmpeg.org/wiki/CompilationGuide/MacOSX。该文档给出了3种方法:

  • ffmpeg through Homebrew
  • Compiling FFmpeg yourself
  • Manual install of the dependencies without Homebrew

看了这三种方法的官方说明后,我选择了第一种,因为最简单。

首先,Mac上要安装Homebrew

在终端执行命令,ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49


devtemobideMac-mini:~ sunminmin$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

==> This script will install:

/usr/local/bin/brew

/usr/local/Library/...

/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort

==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew

Password:

==> Downloading and installing Homebrew...

remote: Counting objects: 225571, done.

remote: Compressing objects: 100% (59354/59354), done.

remote: Total 225571 (delta 165037), reused 225482 (delta 164969)

Receiving objects: 100% (225571/225571), 51.57 MiB | 1.19 MiB/s, done.

Resolving deltas: 100% (165037/165037), done.

From https://github.com/Homebrew/homebrew

* [new branch] master -> origin/master

HEAD is now at 82d7dc4 tomcat: update 8.0.17 bottle.

==> Installation successful!

==> Next steps

Run `brew doctor` before you install anything

Run `brew help` to get started

其次,安装ffmpeg

在终端执行命令,brew install ffmpeg


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40


devtemobideMac-mini:~ sunminmin$ brew install ffmpeg

==> Installing dependencies for ffmpeg: x264, lame, libvo-aacenc, xvid

==> Installing ffmpeg dependency: x264

==> Downloading https://homebrew.bintray.com/bottles/x264-r2533.yosemite.bottle.

######################################################################## 100.0%

==> Pouring x264-r2533.yosemite.bottle.tar.gz

?? /usr/local/Cellar/x264/r2533: 9 files, 3.4M

==> Installing ffmpeg dependency: lame

==> Downloading https://homebrew.bintray.com/bottles/lame-3.99.5.yosemite.bottle

######################################################################## 100.0%

==> Pouring lame-3.99.5.yosemite.bottle.1.tar.gz

?? /usr/local/Cellar/lame/3.99.5: 25 files, 2.1M

==> Installing ffmpeg dependency: libvo-aacenc

==> Downloading https://homebrew.bintray.com/bottles/libvo-aacenc-0.1.3.yosemite

######################################################################## 100.0%

==> Pouring libvo-aacenc-0.1.3.yosemite.bottle.tar.gz

?? /usr/local/Cellar/libvo-aacenc/0.1.3: 15 files, 336K

==> Installing ffmpeg dependency: xvid

==> Downloading https://homebrew.bintray.com/bottles/xvid-1.3.3.yosemite.bottle.

######################################################################## 100.0%

==> Pouring xvid-1.3.3.yosemite.bottle.2.tar.gz

?? /usr/local/Cellar/xvid/1.3.3: 9 files, 1.3M

==> Installing ffmpeg

==> Downloading https://homebrew.bintray.com/bottles/ffmpeg-2.6.3.yosemite.bottle.ta

######################################################################## 100.0%

==> Pouring ffmpeg-2.6.3.yosemite.bottle.tar.gz

==> Caveats

FFmpeg has been built without libfaac for licensing reasons;

libvo-aacenc is used by default.

To install with libfaac, you can:

brew reinstall ffmpeg --with-faac

You can also use the experimental FFmpeg encoder, libfdk-aac, or

libvo_aacenc to encode AAC audio:

ffmpeg -i input.wav -c:a aac -strict experimental output.m4a

Or:

brew reinstall ffmpeg --with-fdk-aac

ffmpeg -i input.wav -c:a libfdk_aac output.m4a

==> Summary

?? /usr/local/Cellar/ffmpeg/2.6.3: 204 files, 42M

再次,查看ffmpeg info

在终端执行命令,brew info ffmpeg


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88


devtemobideMac-mini:~ sunminmin$ brew info ffmpeg

ffmpeg: stable 2.6.3 (bottled), HEAD

Play, record, convert, and stream audio and video

https://ffmpeg.org/

/usr/local/Cellar/ffmpeg/2.6.3 (204 files, 42M) *

Poured from bottle

From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/ffmpeg.rb

==> Dependencies

Build: pkg-config ?, texi2html ?, yasm ?

Recommended: x264 ?, lame ?, libvo-aacenc ?, xvid ?

Optional: faac ?, fontconfig ?, freetype ?, theora ?, libvorbis ?, libvpx ?, rtmpdump ?, opencore-amr ?, libass ?, openjpeg ?, speex ?, schroedinger ?, fdk-aac ?, opus ?, frei0r ?, libcaca ?, libbluray ?, libsoxr ?, libquvi ?, libvidstab ?, x265 ?, openssl ?, libssh ?, webp ?

==> Options

--with-faac

Build with faac support

--with-fdk-aac

Enable the Fraunhofer FDK AAC library

--with-ffplay

Enable FFplay media player

--with-fontconfig

Build with fontconfig support

--with-freetype

Build with freetype support

--with-frei0r

Build with frei0r support

--with-libass

Enable ASS/SSA subtitle format

--with-libbluray

Build with libbluray support

--with-libcaca

Build with libcaca support

--with-libquvi

Build with libquvi 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-openjpeg

Enable JPEG 2000 image format

--with-openssl

Enable SSL support

--with-opus

Build with opus support

--with-rtmpdump

Enable RTMP protocol

--with-schroedinger

Enable Dirac video format

--with-speex

Build with speex support

--with-theora

Build with theora support

--with-tools

Enable additional FFmpeg tools

--with-webp

Enable using libwebp to encode WEBP images

--with-x265

Enable x265 encoder

--without-lame

Disable MP3 encoder

--without-libvo-aacenc

Disable VisualOn AAC encoder

--without-qtkit

Disable deprecated QuickTime framework

--without-x264

Disable H.264 encoder

--without-xvid

Disable Xvid MPEG-4 video encoder

--HEAD

Install HEAD version

==> Caveats

FFmpeg has been built without libfaac for licensing reasons;

libvo-aacenc is used by default.

To install with libfaac, you can:

brew reinstall ffmpeg --with-faac

You can also use the experimental FFmpeg encoder, libfdk-aac, or

libvo_aacenc to encode AAC audio:

ffmpeg -i input.wav -c:a aac -strict experimental output.m4a

Or:

brew reinstall ffmpeg --with-fdk-aac

ffmpeg -i input.wav -c:a libfdk_aac output.m4a

经过这3步,现在就可以使用ffmpeg的强大功能了。

现在ffmpeg的版本更新很快,今年3月份发布了 FFmpeg 2.6.1,7月份发布了 FFmpeg 2.7.2,中间还有一些其它版本,比如2.7,2.7.1,这些版本我都在iOS平台上编译使用过,今年9月份,FFmpeg 的版本更新到了2.8。今年,我见证了FFmpeg更新最频繁的的时刻。

经过前面的3步,在Mac上安装了 ffmpeg 2.6.3 的版本,过段时间,homebrew上ffmpeg 的安装源就会更新,若想升级ffmpeg,就需要执行下面的第4步操作了。

最后,升级ffmpeg的版本

若想升级ffmpeg的版本,可以在终端执行命令,brew update && brew upgrade ffmpeg

实例

安装好了ffmpeg,就要试试其功能了。采用文章利用x264将iOS摄像头实时视频流编码为h264文件配套工程X264-Encode-for-iOS中的h264文件,该文件地址为2015-09-17 18:05:20.h264,使用ffmpeg 命令将其打包为 .mp4容器格式的文件

将该h264文件下载,在终端上,执行命令进入存放该文件的目录


1

devtemobideMac-mini:~ sunminmin$ cd /Users/dev.temobi/Desktop/sunmmMainPrj/ZZ_Z_Github_clone

进入到该目录后,执行命令,ffmpeg -i 2015-09-17\ 18_05_20.h264 2015-09-17.mp4


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48


devtemobideMac-mini:ZZ_Z_Github_clone sunminmin$ ffmpeg -i 2015-09-17\ 18_05_20.h264 2015-09-17.mp4

ffmpeg version 2.6.3 Copyright (c) 2000-2015 the FFmpeg developers

built with Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)

configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda

libavutil 54. 20.100 / 54. 20.100

libavcodec 56. 26.100 / 56. 26.100

libavformat 56. 25.101 / 56. 25.101

libavdevice 56. 4.100 / 56. 4.100

libavfilter 5. 11.102 / 5. 11.102

libavresample 2. 1. 0 / 2. 1. 0

libswscale 3. 1.101 / 3. 1.101

libswresample 1. 1.100 / 1. 1.100

libpostproc 53. 3.100 / 53. 3.100

Input #0, h264, from ‘2015-09-17 18_05_20.h264‘:

Duration: N/A, bitrate: N/A

Stream #0:0: Video: h264 (Constrained Baseline), yuv420p, 480x360, 15 fps, 15 tbr, 1200k tbn, 30 tbc

[libx264 @ 0x7fada2818000] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX

[libx264 @ 0x7fada2818000] profile High, level 2.1

[libx264 @ 0x7fada2818000] 264 - core 144 r2533 c8a773e - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=15 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

Output #0, mp4, to ‘2015-09-17.mp4‘:

Metadata:

encoder : Lavf56.25.101

Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 480x360, q=-1--1, 15 fps, 15360 tbn, 15 tbc

Metadata:

encoder : Lavc56.26.100 libx264

Stream mapping:

Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))

Press [q] to stop, [?] for help

frame= 64 fps=0.0 q=27.0 size= 60kB time=00:00:00.80 bitrate= 609.7kbits/s frame= 87 fps= 85 q=27.0 size= 187kB time=00:00:02.33 bitrate= 655.2kbits/s frame= 120 fps= 77 q=27.0 size= 366kB time=00:00:04.53 bitrate= 661.5kbits/s frame= 149 fps= 72 q=27.0 size= 444kB time=00:00:06.46 bitrate= 562.4kbits/s frame= 178 fps= 69 q=27.0 size= 508kB time=00:00:08.40 bitrate= 495.4kbits/s frame= 196 fps= 56 q=-1.0 Lsize= 651kB time=00:00:12.93 bitrate= 412.2kbits/s

video:648kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.389284%

[libx264 @ 0x7fada2818000] frame I:2 Avg QP:20.10 size: 5888

[libx264 @ 0x7fada2818000] frame P:126 Avg QP:22.22 size: 4340

[libx264 @ 0x7fada2818000] frame B:68 Avg QP:23.94 size: 1537

[libx264 @ 0x7fada2818000] consecutive B-frames: 43.9% 27.6% 6.1% 22.4%

[libx264 @ 0x7fada2818000] mb I I16..4: 31.4% 51.4% 17.2%

[libx264 @ 0x7fada2818000] mb P I16..4: 8.6% 10.2% 4.6% P16..4: 46.2% 11.9% 4.2% 0.0% 0.0% skip:14.2%

[libx264 @ 0x7fada2818000] mb B I16..4: 1.1% 0.6% 0.6% B16..8: 52.3% 4.9% 0.8% direct: 3.2% skip:36.5% L0:51.0% L1:45.1% BI: 3.9%

[libx264 @ 0x7fada2818000] 8x8 transform intra:43.2% inter:63.2%

[libx264 @ 0x7fada2818000] coded y,uvDC,uvAC intra: 42.6% 57.1% 10.4% inter: 19.2% 28.2% 0.7%

[libx264 @ 0x7fada2818000] i16 v,h,dc,p: 20% 51% 10% 19%

[libx264 @ 0x7fada2818000] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 24% 38% 22% 2% 2% 2% 4% 2% 5%

[libx264 @ 0x7fada2818000] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 43% 12% 3% 3% 3% 6% 4% 5%

[libx264 @ 0x7fada2818000] i8c dc,h,v,p: 51% 32% 14% 3%

[libx264 @ 0x7fada2818000] Weighted P-Frames: Y:7.1% UV:5.6%

[libx264 @ 0x7fada2818000] ref P L0: 78.9% 10.4% 8.3% 2.3% 0.1%

[libx264 @ 0x7fada2818000] ref B L0: 93.9% 5.6% 0.5%

[libx264 @ 0x7fada2818000] ref B L1: 96.2% 3.8%

[libx264 @ 0x7fada2818000] kb/s:405.98

到此,h264文件封装为.mp4格式的过程结束。

查看2015-09-17.mp4 文件,如图

2015-09-17.mp4 文件可以使用Quick Time Player,VLC 正常播放。

坚持原创思维分享,您的支持将鼓励我继续创作!

时间: 2024-12-04 10:05:43

在Mac OSX上安装ffmpeg && ffmpeg命令行将h264封装为mp4的相关文章

如何在Mac OSX上安装xgboost

听说xgboost效果很不错,于是准备学习下,但是发现大多数资料都是在讲如何在windows或linux下安装xgboost,而且照着官方文档也没有正确的安装好多线程的xgboost.最后还是从there找到了方法. 1. Mac OSX系统一般自带python,打开终端输入python即可写python代码,所以python环境已经具备了. 2.安装 Homebrew , 类似于ubuntu中的apt-get和centos中的yum,是OSX里面的一个非常有用软件安装工具. /usr/bin/

Mac/OSX上安装xshell

xshell没有mac版,且不愿意仅为一个程序运行一个虚拟机.怎么办?装上wine个来跑shell吧! 1.安装 WineBottler 过程略(制作.管理windows程序,类似CrossOver).2.下载 xshell 安装包,亲测 xshell 4可以正常安装使用,xshell 5的C++运行库安装失败.3.打开 WineBottler ,官方带了一些程序可以一键安装使用.4.xshell 需要手动做,简单配置一下即可.如图:5.安装过程有弹窗,手动点下一步咯(CrossOver会卡在弹

在 Mac OSX 上安装 nginx

今天在使用 brew 安装 nginx 时,提示错误,安装不上去: brew install nginx, 提示:/usr/local is not writable. 这个是需要修改 /usr/local 目录的权限: sudo chown -R $(whoami) /usr/local 执行此命令后, 再执行 brew install nginx 即可安装.

Mac OSX上的软件包管理工具,brew 即 Homebrew

brew 即 Homebrew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件, 只需要一个命令, 非常方便. brew类似ubuntu系统下的apt-get的功能. 安装brew: curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local --strip 1 安装软件:brew install cgdb 卸载软件:brew uninstall cgdb

在Mac OSX 上配置Appium+Android自动化测试环境

前提准备 开始正文之前,你需要准备好一些基本条件: 安装好Mac OSX 操作系统的设备 能够访问中国局域网以外资源的方法(没有也行,但很痛苦) 已经安装好 homebrew 已经安装好 Python3.x 已经安装好 Java Runtime Environment 安装 Android Studio / SDK 本文主要为了测试安卓应用,那么这里我们就需要安装Android Studio或者Android SDK. Android Studio - 完整的开发以及测试工具,需要梯子 Andr

mac osx下安装mysql

操作系统版本:mac osx 10.11mysql版本:官网下载dmg  v5.6.33  https://www.mysql.com/ 安装步骤1.双击dmg安装2.开启mysql服务系统偏好设置-底部-mysql-打开服务这个时候还不能使用mysql命令,需要配置mysql命令的路径. 3.配置环境变量mysql的路径在当前用户根目录下编辑.bash_profile文件,添加一行:export PATH=${PATH}:/usr/local/mysql/bin 注:/usr/local/my

在Mac OS上安装Vagrant和Docker的教程

转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/128.html?1455808640 当听到很多人在说Docker是多么多么的棒,很多新潮的孩子都在使用它时,我决定在我的开发环境上也来尝试下.在下面的这篇文章中,我将讲解在Mac OS X怎样建立Postgres,Elasticsearch和Redis. 什么是Docker Docker用轻量容器把一个APP从它运行的OS中隔离开.它把APP放入到一个孤立的盒子中,对外

在Mac pro上如何配置adb命令?

在Mac pro上如何将Android SDK的adb命令添加到环境变量中,这里将进行说明! 方法/步骤 1 启动终端,可以在Spotlight中搜索“终端” 2 进入当前用户的HOME目录,命令如下: cd $HOME 3 更新.bash_profile文件(当该文件存在时),如果该文件不存在,可通过如下命令创建: touch .bash_profile 4 打开.bash_profile文件,对其内容进行编辑,命令如下: open -e .bash_profile 5 此时文本编辑器会打开一

Mac(Linux)上安装memcached步骤

Mac上安装memcached类似于在Linux平台上安装memcached. 主要需要做两块: 一.安装libevent库: 二.安装memcached; 一.安装libevent库 libevent是个程序库,它将Linux的epoll.BSD类操作系统的kqueue等事件处理功能 封装成统一的接口.即使对服务器的连接数增加,也能发挥O(1)的性能. memcached使用这个libevent库,因此能在Linux.BSD.Solaris等操作系统上发挥其高性能. 关于事件处理这里就不再详细