音频处理神器 FFmpeg安装与使用
每一位做音频处理的开发者想必都离不开FFmpeg。在语音识别ASR任务中,也常需要对音视频进行格式转换(如opus/mp3/aac/mp4转成wav)、重采样及通道转换等。而这些复杂功能仅需要一个FFmpeg即可做到。下面笔者将向大家介绍一下FFmpeg的安装及使用,后续将持续分享源码级别的使用技巧。
FFmpeg的安装
以centos为例
1. 安装基础依赖
yum install autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make pkgconfig
yum install zlib zlib-devel curl curl-devel alsa-lib alsa-lib-devel gettext gettext-devel expat expat-devel gnutls gnutls-devel bzip2 bzip2-devel -y
2.安装三方库
2.1 NASM
wget https://www.nasm.us/pub/nasm/releasebuilds/2.15.05/nasm-2.15.05.tar.xz
xz -d nasm-2.15.05.tar.xz
tar xvf nasm-2.15.05.tar
cd nasm-2.15.05
./configure --prefix=/usr
make
make install
2.2 安装YASM
wget https://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xzvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure --prefix=/usr
make
make install
2.3 安装x264
wget https://anduin.linuxfromscratch.org/BLFS/x264/x264-20210211.tar.xz
xz -d x264-20210211.tar.xz
tar xvf x264-20210211.tar
cd x264-20210211
./configure --prefix=/usr/local/ffmpeg --enable-shared --disable-cli
make
make install
2.4 安装x265
wget https://anduin.linuxfromscratch.org/BLFS/x265/x265_3.4.tar.gz
tar xzvf x265_3.4.tar.gz
cd x265_3.4
mkdir bld && cd bld
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/ffmpeg ../source
make
make install
rm -vf /usr/local/ffmpeg/lib/libx265.a
2.5 安装fdk-aac
wget https://downloads.sourceforge.net/opencore-amr/fdk-aac-2.0.2.tar.gz
tar xzvf fdk-aac-2.0.2.tar.gz
cd fdk-aac-2.0.2
./configure --prefix=/usr/local/ffmpeg --disable-static
make
make install
2.6 安装lame
wget https://downloads.sourceforge.net/lame/lame-3.100.tar.gz
tar xzvf lame-3.100.tar.gz
cd lame-3.100
./configure --prefix=/usr/local/ffmpeg --enable-mp3rtp --disable-static
make
make pkghtmldir=/usr/local/ffmpeg/share/doc/lame-3.100 install
2.7 安装opus解码器
wget https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz
tar xzvf opus-1.3.1.tar.gz
cd opus-1.3.1
./configure --prefix=/usr/local/ffmpeg --disable-static --docdir=/usr/share/doc/opus-1.3.1
make
make install
2.8 安装libvpx
wget https://github.com/webmproject/libvpx/archive/v1.10.0/libvpx-1.10.0.tar.gz
tar xzvf libvpx-1.10.0.tar.gz
cd libvpx-1.10.0
sed -i 's/cp -p/cp/' build/make/Makefile
mkdir libvpx-build && cd libvpx-build
../configure --prefix=/usr/local/ffmpeg --enable-shared --disable-static
make
make install
2.9 安装freetype2
apt install libfreetype6-dev
2.10 安装openssl
apt-get install openssl
apt-get install libssl-dev
3. 安装FFmpeg
wget https://ffmpeg.org/releases/ffmpeg-4.4.tar.xz
tar jxvf ffmpeg-4.4.tar.bz2
cd ffmpeg-4.4
export PATH="/usr/local/ffmpeg/bin:$PATH"
export PKG_CONFIG_PATH="/usr/local/ffmpeg/lib/pkgconfig"
./configure --prefix=/usr/local/ffmpeg --pkg-config-flags="--static" --extra-cflags="-I/usr/local/ffmpeg/include" --extra-ldflags="-L/usr/local/ffmpeg/lib" --enable-gpl --enable-version3 --enable-nonfree --disable-static --enable-shared --disable-debug --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libx264 --enable-libx265 --enable-openssl
make
make install
hash -d ffmpeg
FFmpeg的基本使用
指令篇
wav to mp3
ffmpeg -i audio.wav -acodec libmp3lame audio.mp3
wav to ogg
ffmpeg -i audio.wav -acodec libvorbis audio.ogg
wav to acc
ffmpeg -i audio.wav -acodec libfaac audio.aac
wav to ac3
ffmpeg -i audio.wav -acodec ac3 audio.ac3
ogg to mp3
ffmpeg -i audio.ogg -acodec libmp3lame audio.mp3
ogg to wav
ffmpeg -i audio.ogg audio.wav
ogg to aac
ffmpeg -i audio.ogg -acodec libfaac audio.aac
ogg to ac3
ffmpeg -i audio.ogg -acodec ac3 audio.ac3
ac3 to mp3
ffmpeg -i audio.ac3 -acodec libmp3lame audio.mp3
ac3 to wav
ffmpeg -i audio.ac3 audio.wav
ac3 to acc
ffmpeg -i audio.ac3 -acodec libfaac audio.aac
ac3 to ogg
ffmpeg -i audio.ac3 -acodec libvorbis audio.ogg
- 点赞
- 收藏
- 关注作者
评论(0)