0%

FFmpeg

了解

FFmpeg是一个音视频处理库,提供了如 ffmpeg, ffplay, ffprobe,来编辑你的音视频文件。

安装

源码安装

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
➜  GitHub git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
Cloning into 'ffmpeg'...
remote: Counting objects: 588505, done.
remote: Compressing objects: 100% (120835/120835), done.
remote: Total 588505 (delta 471727), reused 581424 (delta 466456)
Receiving objects: 100% (588505/588505), 138.43 MiB | 2.74 MiB/s, done.
Resolving deltas: 100% (471727/471727), done.
Checking out files: 100% (7264/7264), done.
➜ GitHub cd ffmpeg
➜ ffmpeg git:(master) ls
CONTRIBUTING.md LICENSE.md ffbuild libpostproc
COPYING.GPLv2 MAINTAINERS fftools libswresample
COPYING.GPLv3 Makefile libavcodec libswscale
COPYING.LGPLv2.1 README.md libavdevice presets
COPYING.LGPLv3 RELEASE libavfilter tests
CREDITS compat libavformat tools
Changelog configure libavresample
INSTALL.md doc libavutil
➜ ffmpeg git:(master) ./configure --help
➜ ffmpeg git:(master) ./configure --help | more
Usage: configure [options]
Options: [defaults in brackets after descriptions]

➜ ffmpeg git:(master) ./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libx264 --enable-libx265 --enable-filter=delogo --enable-debug --disable-optimizations --enable-libspeex --enable-videotoolbox --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --cc=clang --host-cflags= --host-ldflags=


报错、报错、报错、报错、
nasm/yasm not found or too old. Use --disable-x86asm for a crippled build.
ERROR: libfdk_aac not found
ERROR: speex not found using pkg-config
ERROR: libx264 not found

前面三种都可以通过brew install来解决,但是libx264怎么搞都拉不下。。。

通过brew安装

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
➜  ffmpeg git:(master) brew install ffmpeg
Updating Homebrew...
==> Installing dependencies for ffmpeg: aom,,,,

==> Caveats
gettext is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.

If you need to have gettext first in your PATH run:
echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.zshrc

For compilers to find gettext you may need to set:
export LDFLAGS="-L/usr/local/opt/gettext/lib"
export CPPFLAGS="-I/usr/local/opt/gettext/include"
==> Caveats
libffi is keg-only, which means it was not symlinked into /usr/local,
because some formulae require a newer version of libffi.

For compilers to find libffi you may need to set:
export LDFLAGS="-L/usr/local/opt/libffi/lib"

For pkg-config to find libffi you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"


==> Caveats
==> gettext
gettext is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD gettext library & some software gets confused if both are in the library path.

If you need to have gettext first in your PATH run:
echo 'export PATH="/usr/local/opt/gettext/bin:$PATH"' >> ~/.zshrc

For compilers to find gettext you may need to set:
export LDFLAGS="-L/usr/local/opt/gettext/lib"
export CPPFLAGS="-I/usr/local/opt/gettext/include"

==> libffi
libffi is keg-only, which means it was not symlinked into /usr/local,
because some formulae require a newer version of libffi.

For compilers to find libffi you may need to set:
export LDFLAGS="-L/usr/local/opt/libffi/lib"

For pkg-config to find libffi you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"

==> unbound
To have launchd start unbound now and restart at startup:
sudo brew services start unbound
==> glib
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> tesseract
This formula contains only the "eng", "osd", and "snum" language data files.
If you need any other supported languages, run `brew install tesseract-lang`.

brew info ffmpeg可以看到x264, x265这些包都是有安装的。升级则通过brew update && brew upgrade ffmpeg.

第二种方式安装连环境变量都不需要设置,完美极了。

目录及作用

  • libavcodec: 提供了一系列编码器的实现。
  • libavformat: 实现在流协议,容器格式及其本IO访问。
  • libavutil: 包括了hash器,解码器和各利工具函数。
  • libavfilter: 提供了各种音视频过滤器。
  • libavdevice: 提供了访问捕获设备和回放设备的接口。
  • libswresample: 实现了混音和重采样。
  • libswscale: 实现了色彩转换和缩放工能。

基本概念

音/视频流 在音视频领域,我们把一路音/视频称为一路流。如我们小时候经常使用VCD看港片,在里边可以选择粤语或国语声音,其实就是CD视频文件中存放了两路音频流,用户可以选择其中一路进行播放。

容器 我们一般把 MP4、 FLV、MOV等文件格式称之为容器。也就是在这些常用格式文件中,可以存放多路音视频文件。以 MP4 为例,就可以存放一路视频流,多路音频流,多路字幕流。

channel 是音频中的概念,称之为声道。在一路音频流中,可以有单声道,双声道或立体声。

参考链接:

https://blog.csdn.net/weixin_33985507/article/details/94470495

https://blog.csdn.net/leixiaohua1020/article/details/15811977