2

FFmpeg开发笔记(十)Linux环境给FFmpeg集成vorbis和amr - aqi00

 1 month ago
source link: https://www.cnblogs.com/aqi00/p/18078414
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

​FFmpeg内置了aac音频格式,在《FFmpeg开发实战:从零基础到短视频上线》一书的“5.2.2  Linux环境集成mp3lame”又介绍了如何给FFmpeg集成mp3格式,常见的音频文件除了这两种之外,还有ogg和amr两种格式也较常用。其中ogg格式的编解码依赖于libogg和libvorbis,而amr格式的编解码依赖于opencore-amr。因此要先安装编译这三个库,再让FFmpeg开启ogg和amr支持,在Linux环境的操作过程包含四个步骤:安装libogg、安装libvorbis、安装opencore-amr、重新编译FFmpeg,分别说明如下。

1、安装libogg

libogg支持解析ogg文件结构,也可用于封装ogg格式,它的安装步骤说明如下。
(1)到https://www.linuxfromscratch.org/blfs/view/svn/multimedia/libogg.html下载最新的libogg源码,比如2021年6月发布的libogg-1.3.5,该版本的源码下载地址是https://downloads.xiph.org/releases/ogg/libogg-1.3.5.tar.gz。将下载好的压缩包上传到服务器并解压,也就是依次执行以下命令。

tar zxvf libogg-1.3.5.tar.gz
cd libogg-1.3.5

(2)进入解压后的libogg目录,运行下面命令配置libogg。

./configure
729938-20240317121526913-1276182245.gif

(3)运行下面命令编译libogg。

make

(4)编译完成后,运行下面命令安装libogg。

make install

2、安装libvorbis

Vorbis是一种免费的音频编码标准,libvorbis是Vorbis音频的编解码库。因为Vorbis音频通常封装在ogg格式中,所以libvorbis依赖于libogg,它的安装步骤说明如下。
(1)到https://www.linuxfromscratch.org/blfs/view/svn/multimedia/libvorbis.html下载最新的libvorbis源码,比如2020年7月发布的libvorbis-1.3.7,该版本的源码下载地址是https://downloads.xiph.org/releases/vorbis/libvorbis-1.3.7.tar.gz。将下载好的压缩包上传到服务器并解压,也就是依次执行以下命令。

tar zxvf libvorbis-1.3.7.tar.gz
cd libvorbis-1.3.7

(2)进入解压后的libvorbis目录,运行下面命令配置libvorbis。

./configure

(3)运行下面命令编译libvorbis。

make

(4)编译完成后,运行下面命令安装libvorbis。

make install

3、安装opencore-amr

opencore-amr是AMR音频的编解码库,支持对AMR-NB和AMR-WB格式的音频进行编解码,它的安装步骤说明如下。
(1)到https://sourceforge.net/projects/opencore-amr/files/opencore-amr/下载最新的opencore-amr源码,比如2022年10月发布的opencore-amr-0.1.6,该版本的源码下载地址是https://nchc.dl.sourceforge.net/project/opencore-amr/opencore-amr/opencore-amr-0.1.6.tar.gz。将下载好的压缩包上传到服务器并解压,也就是依次执行以下命令。

tar zxvf opencore-amr-0.1.6.tar.gz
cd opencore-amr-0.1.6
729938-20240317121526913-1276182245.gif

(2)进入解压后的opencore-amr目录,运行下面命令配置opencore-amr。

./configure

(3)运行下面命令编译opencore-amr。

make

(4)编译完成后,运行下面命令安装opencore-amr。

make install

4、重新编译FFmpeg

由于FFmpeg默认未启用ogg和amr,因此需要重新配置FFmpeg,标明启用ogg和amr,然后重新编译安装FFmpeg。FFmpeg的Linux环境完整编译过程参见《FFmpeg开发实战:从零基础到短视频上线》一书的“1.2.3  自行编译与安装FFmpeg”,详细的启用步骤说明如下。
(1)回到FFmpeg源码的目录,执行以下命令重新配置FFmpeg,主要增加启用ogg和amr。(增加了选项--enable-libvorbis --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3)

./configure --prefix=/usr/local/ffmpeg --enable-shared --disable-static --disable-doc --enable-zlib --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libdavs2 --enable-libmp3lame --enable-libfreetype --enable-libass --enable-libfribidi --enable-libxml2 --enable-fontconfig --enable-sdl2 --enable-libvorbis --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-iconv --enable-gpl --enable-nonfree

(2)运行下面命令编译FFmpeg。

make clean
make -j4

(3)执行下面命令安装FFmpeg。

make install

(4)运行以下命令查看FFmpeg的版本信息。

ffmpeg -version

查看控制台回显的FFmpeg版本信息,找到“--enable-libvorbis --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3”,说明FFmpeg正确启用了新增的音频格式ogg和amr。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK