Linux下ffmpeg的安装

 ffmpeg是一个很强大的音视频处理工具,官网是:http://ffmpeg.org/ 官网介绍ffmpeg是:一个完整的、跨平台的解决方案,可以记录、转换和传输音频和视频。ffmpeg既可以播放视频,也提供命令行工具来处理视频,另外还有强大的视频处理库用于开发,下面是以Linux为例介绍ffmpeg的安装流程的简单的命令行对视频进行转码操作,是ffmpeg中最最简单的入门内容.
 ffmpeg自带了很多的解码器,但是编码器不是很多,如果有特殊需求的话需要自己手动下载编译安装各种编码器.
 这里我只安装了一部分的编码器,其它的同理.
 首先获得管理员权限,后面的基本所有命令都是需要管理员权限运行的,所以方便起见,直接登陆管理员身份,不需要每个命令都加sudo.

sudo su

1.lame
lame-3.100.tar.gz
下载地址:http://sourceforge.net/project/showfiles.php?group_id=290&package_id=309
安装方法如下:

tar -zxvf lame-3.100.tar.gz
cd lame-3.100
./configure
make
make install
make clean
cd ../

2.libogg
libogg-1.3.3.tar.gz
下载地址:http://download.csdn.net/download/tuzixini/10133787
安装方法如下:

tar -zxvf libogg-1.3.3.tar.gz
cd libogg-1.3.3
./configure
make
make install
make clean
cd ../

3.libvorbis
libvorbis-1.3.3.tar.xz
下载地址:http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz
(libvorbis依赖于libogg, 所以libogg必须先于libvorbis安装)
安装方法如下:

tar -zxvf libvorbis-1.3.3.tar.xz
cd libvorbis-1.3.5
./configure
make
make install
make clean
cd ../

4.xvid
这个编码器是个磨人的小妖精,就是它耽误了我一个下午,说是安装ffmpeg其实全是在搞他.一定要注意它的版本!!!!!一定要新版的!!!!!!!!!!1.3.3,后面会说它导致的各种问题!!!!!!!!!
xvidcore-1.3.3.tar.gz
下载地址:http://download.csdn.net/download/tuzixini/10133790
安装方法如下:

tar -zxvf xvidcore-1.3.3.tar.gz
cd xvidcore-1.3.3/build/generic/
./configure
make
make install
make clean
cd ../../../

5、x264
latest_x264.tar.bz2 (其中包含的目录是 x264-snapshot-20131023-2245)
下载地址:http://download.csdn.net/download/tuzixini/10133786

tar -zxvf latest_x264.tar.bz2 
cd x264-snapshot-20131023-2245
./configure --enable-shared --enable-static
make
make install
make clean
cd ../

至此为止,安装好了所有我需要的编码器,然后下面安装ffmpeg
6.ffmpeg
ffmpeg-3.4.tar.bz2
下载地址:http://download.csdn.net/download/tuzixini/10133792

tar -zxvf ffmpeg-3.4.tar.bz2
cd ffmpeg-3.4
./configure --enable-shared --prefix=/usr/local/ffmpeg --enable-libmp3lame --enable-gpl --enable-version3 --enable-nonfree --enable-pthreads --enable-postproc --enable-ffserver --enable-ffplay --enable-libx264 --enable-libxvid
make
make install
make clean
cd ../

编译十分十分十分十分十分的慢,耐心等待………
7.编译完成之后,修改一下/etc/profile文件,把ffmpeg加入环境变量中.

echo "export PATH=/usr/local/ffmpeg/bin:$PATH" >> /etc/profile
source /etc/profile

8.把ffmpeg的库加入/etc/ld.so.conf中

echo "/usr/local/ffmpeg/lib" >> /etc/ld.so.conf
ldconfig

然后运行

ffmpeg -version

如果一切都没有问题的话应该是如下结果:

ffmpeg version 3.3.2-1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.4.0 (Debian 6.4.0-2) 20170724
  configuration: --prefix=/usr --extra-version=1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

如果看到了这个输出,那么恭喜你,安装完成!!

如果你很不幸,,
在编译ffmpeg的时候出现了如下错误:

libavcodec/libxvid.c: In function ‘xvid_encode_init’:
libavcodec/libxvid.c:384:5: error: unknown type name ‘xvid_plugin_lumimasking_t’
     xvid_plugin_lumimasking_t masking_l       = { 0 }; /* For lumi masking */
     ^~~~~~~~~~~~~~~~~~~~~~~~~
libavcodec/libxvid.c:385:5: error: unknown type name ‘xvid_plugin_lumimasking_t’
     xvid_plugin_lumimasking_t masking_v       = { 0 }; /* For variance AQ */
     ^~~~~~~~~~~~~~~~~~~~~~~~~
libavcodec/libxvid.c:386:5: error: unknown type name ‘xvid_plugin_ssim_t’
     xvid_plugin_ssim_t        ssim            = { 0 };
     ^~~~~~~~~~~~~~~~~~
libavcodec/libxvid.c:589:18: error: request for member ‘method’ in something not a structure or union
         masking_l.method                          = 0;
                  ^
libavcodec/libxvid.c:601:18: error: request for member ‘method’ in something not a structure or union
         masking_v.method                           = 1;
                  ^
libavcodec/libxvid.c:614:54: error: ‘xvid_plugin_ssim’ undeclared (first use in this function)
         plugins[xvid_enc_create.num_plugins].func  = xvid_plugin_ssim;
                                                      ^~~~~~~~~~~~~~~~
libavcodec/libxvid.c:614:54: note: each undeclared identifier is reported only once for each function it appears in
libavcodec/libxvid.c:615:13: error: request for member ‘b_printstat’ in something not a structure or union
         ssim.b_printstat                           = x->ssim == 2;
             ^
libavcodec/libxvid.c:616:13: error: request for member ‘acc’ in something not a structure or union
         ssim.acc                                   = x->ssim_acc;
             ^
libavcodec/libxvid.c:617:13: error: request for member ‘cpu_flags’ in something not a structure or union
         ssim.cpu_flags                             = xvid_gbl_init.cpu_flags;
             ^
libavcodec/libxvid.c:618:13: error: request for member ‘b_visualize’ in something not a structure or union
         ssim.b_visualize                           = 0;
             ^
ffbuild/common.mak:60: recipe for target 'libavcodec/libxvid.o' failed
make: *** [libavcodec/libxvid.o] Error 1

那么你可以选择在编译ffmpeg的时候去掉”–enable-libxvid”的选项,也就是更改第六步为:
6.ffmpeg
ffmpeg-3.4.tar.bz2
下载地址:http://ffmpeg.org/

tar -zxvf ffmpeg-3.4.tar.bz2
cd ffmpeg-3.4
./configure --enable-shared --prefix=/usr/local/ffmpeg --enable-libmp3lame --enable-gpl --enable-version3 --enable-nonfree --enable-pthreads --enable-postproc --enable-ffserver --enable-ffplay --enable-libx264
make
make install
make clean
cd ../

然后再进行第七步如果你很幸运,那么可以正常使用,恭喜你.
但是你还有可能会出现无法运行ffmpeg的情况,如果运行”ffmpeg -version”遇到如下错误:

ffmpeg: symbol lookup error: /usr/lib/x86_64-linux-gnu/libavcodec.so.57: undefined symbol: xvid_plugin_ssim

那么首先检查第八步中修改的文件是否具有如下内容:

cat /etc/ld.so.conf

如果内容如下:

include /etc/ld.so.conf.d/*.conf
/usr/local/ffmpeg/lib

那么请运行如下命令(管理员权限下)后再次运行”ffmpeg -version”

ldconfig

如果还是报出同样错误的话,那么恭喜你,你可能是用了低版本的xvid编码器,所以之前进行第四步的时候我就提示一定不要下载错了文件!!现在重新检查一下你下载的xvid编码器版本!!要1.3.3版本的才行!!!确认无误之后重新进行第四步以及第六步完成之后进行第七步检验是否安装成功.(就是这个坑爹的问题困扰了我好长好长时间,还查不到资料………….)

记住这一切都是..玄学,祝好运.

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值