安装ffmpeg
1、先下载ffmpeg的安装包,下载地址如下:Download FFmpeg
本次使用的是6.0.1版本
2、下载后上传至linux系统
3、解压安装包报错
tar -xvf ffmpeg-6.0.1.tar.bz2
这里不使用 tar -zxvf XXX命令是因为会报错,这个安装包不是zip压缩的
3.1、安装bzip
yum install -y bzip2
3.2、安装好bzip2之后再次执行tar -xvf ffmpeg-6.0.1.tar.bz2然后就成功解压
4、安装ffmpeg
进入解压后的文件夹,执行配置文件然后就开始安装。
这里有个坑,就是一定要加--enable-libmp3lame,因为我是需要把amr文件转成MP3文件的,必须要用到libmp3lame,否则后面格式转换文件为空。
cd ffmpeg-6.0.1
./configure --enable-shared --enable-libmp3lame
make;make install
报错ERROR: libmp3lame >= 3.98.3 not found
解决办法:安装lame-3.100
解压安装三件套
tar -zxvf lame-3.100.tar.gz
cd lame-3.100
./configure
make;make install
回来继续执行./configure --enable-shared --enable-libmp3lame,这回就成功了。
有时候其实还会报错yasm not found or too old.
只需要安装yasm就行,可以参考Linux环境安装配置ffmpeg_linux安装ffmpeg_西山点子王的博客-CSDN博客中的内容。
make;make install这一步消耗的时间比较长大概十几分钟。
5、检查下是否安装完成,并做在/usr/bin目录下做一个链接,这样全局可用ffmpeg命令。
然后其中还需要配置一下系统环境,否则会报错:ffmpeg: error while loading shared libraries: libavdevice.so.60: cannot open shared object
编辑 /etc/ld.so.conf
vim /etc/ld.so.conf
在最后一行加上
/usr/local/lib
使配置生效
ldconfig
[root@ecs-80782362-002 ffmpeg-6.0.1]# which ffmpeg
/usr/local/bin/ffmpeg
[root@ecs-80782362-002 ffmpeg-6.0.1]# ln -s /usr/local/bin/ffmpeg /usr/bin/ffmpeg
[root@ecs-80782362-002 ffmpeg-6.0.1]# ffmpeg
ffmpeg: error while loading shared libraries: libavdevice.so.60: cannot open shared object file: No such file or directory
[root@ecs-80782362-002 ffmpeg-6.0.1]# vim /etc/ld.so.conf
[root@ecs-80782362-002 ffmpeg-6.0.1]# ldconfig
[root@ecs-80782362-002 ffmpeg-6.0.1]# ffmpeg
ffmpeg version 6.0.1 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-44)
configuration: --enable-shared --enable-libmp3lame
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
Use -h to get full help or, even better, run 'man ffmpeg'
[root@ecs-80782362-002 ffmpeg-6.0.1]#
测试转码
执行命令 ffmpeg -i testvoice.amr testvoice.mp3
我们可以看到已经正常转码完成了,下载下来播放一下音频也是正常的。
[root@ecs-80782362-002 cwwtest]# ll
total 15024
drwx------ 17 servman servman 4096 Nov 30 12:11 ffmpeg-6.0.1
-rw-rw-rw- 1 root root 12335748 Nov 30 11:26 ffmpeg-6.0.1.tar.bz2
drwxr-xr-x 15 1001 1001 4096 Nov 30 11:59 lame-3.100
-rw-rw-rw- 1 root root 1524133 Nov 30 11:57 lame-3.100.tar.gz
-rw-rw-rw- 1 root root 11078 Nov 30 13:38 testvoice.amr
drwxrwxr-x 13 servman servman 4096 Nov 29 16:12 yasm-1.3.0
-rw-r--r-- 1 root root 1492156 Aug 11 2014 yasm-1.3.0.tar.gz
[root@ecs-80782362-002 cwwtest]# ffmpeg -i testvoice.amr testvoice.mp3
ffmpeg version 6.0.1 Copyright (c) 2000-2023 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-44)
configuration: --enable-shared --enable-libmp3lame
libavutil 58. 2.100 / 58. 2.100
libavcodec 60. 3.100 / 60. 3.100
libavformat 60. 3.100 / 60. 3.100
libavdevice 60. 1.100 / 60. 1.100
libavfilter 9. 3.100 / 9. 3.100
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
[amr @ 0x2474180] Estimating duration from bitrate, this may be inaccurate
Input #0, amr, from 'testvoice.amr':
Duration: 00:00:07.14, bitrate: 12 kb/s
Stream #0:0: Audio: amr_nb (samr / 0x726D6173), 8000 Hz, mono, fltp, 12 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (amr_nb (amrnb) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'testvoice.mp3':
Metadata:
TSSE : Lavf60.3.100
Stream #0:0: Audio: mp3, 8000 Hz, mono, fltp
Metadata:
encoder : Lavc60.3.100 libmp3lame
size= 7kB time=00:00:06.91 bitrate= 8.5kbits/s speed= 165x
video:0kB audio:7kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 3.647587%
[root@ecs-80782362-002 cwwtest]# ll
total 15032
drwx------ 17 servman servman 4096 Nov 30 12:11 ffmpeg-6.0.1
-rw-rw-rw- 1 root root 12335748 Nov 30 11:26 ffmpeg-6.0.1.tar.bz2
drwxr-xr-x 15 1001 1001 4096 Nov 30 11:59 lame-3.100
-rw-rw-rw- 1 root root 1524133 Nov 30 11:57 lame-3.100.tar.gz
-rw-rw-rw- 1 root root 11078 Nov 30 13:38 testvoice.amr
-rw-r--r-- 1 root root 7388 Nov 30 13:39 testvoice.mp3
drwxrwxr-x 13 servman servman 4096 Nov 29 16:12 yasm-1.3.0
-rw-r--r-- 1 root root 1492156 Aug 11 2014 yasm-1.3.0.tar.gz
[root@ecs-80782362-002 cwwtest]#