一、ffmpeg 在centos7 下的环境搭建
#1.安装编译所需依赖环境
yum install -y automake autoconf libtool gcc gcc-c++
#2.创建文件夹
cd /home/
mkdir soft
#3.安装yasm编译支持
cd /home/soft
wget http://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
make
make install
#4.安装lame MP3解码依赖
cd /home/soft
wget http://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
tar -xzvf lame-3.99.5.tar.gz
cd lame-3.99.5
./configure
make
make install
#5.安装并尝试运行fmpeg命令
cd /home/soft
wget https://ffmpeg.org/releases/ffmpeg-4.1.tar.bz2
tar xjvf ffmpeg-4.1.tar.bz2
cd ffmpeg-4.1
./configure --enable-libmp3lame --enable-shared
make
make install
ffmpeg -version
#会报错以下信息:
#ffmpeg: error while loading shared libraries: libavdevice.so.58: cannot open shared object file: No such file or directory
vi /etc/ld.so.conf
i
#指定动态库链接,默认装在这里了:
/usr/local/lib
:wq
#生效
ldconfig
#再次运行
ffmpeg -version
#会提示以下信息
#ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers
#built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-36)
#configuration: --enable-libmp3lame --enable-shared
#libavutil 56. 22.100 / 56. 22.100
#libavcodec 58. 35.100 / 58. 35.100
#libavformat 58. 20.100 / 58. 20.100
#libavdevice 58. 5.100 / 58. 5.100
#libavfilter 7. 40.101 / 7. 40.101
#libswscale 5. 3.100 / 5. 3.100
#libswresample 3. 3.100 / 3. 3.100
###ffmpeg 常用命令
#1.MP3时长截取
ffmpeg -y -i test.mp3 -ss 00:00:00 -t 00:00:03 -acodec copy output_mp3.mp3
#2.mp3转pcm
ffmpeg -y -i test.mp3 -acodec pcm_s16le -f s16le -ac 2 -ar 16000 16k.pcm
#3.pcm转MP3
ffmpeg -y -f s16be -ac 2 -ar 16000 -acodec pcm_s16le -i 16k.pcm new_mp3.mp3
参考资料:
1.ffmpeg处理pcm和mp3互转
https://segmentfault.com/a/1190000016652277
2.Linux 编译升级 Ffmpeg 步骤
https://blog.csdn.net/defonds/article/details/9698959
3.Linux环境ffmpeg以及相应解码器安装