天天看点

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.tar.gz
cd lame
./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.tar.gz
cd libogg
./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.tar.xz
cd libvorbis
./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.tar.gz
cd xvidcore/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--
./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-.tar.bz2
cd ffmpeg-
./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 - Copyright (c) - the FFmpeg developers
  built with gcc  (Debian -) 
  configuration: --prefix=/usr --extra-version= --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        /  
  libavcodec       /  
  libavformat      /  
  libavdevice       /   
  libavfilter       /   
  libavresample        /      
  libswscale         /    
  libswresample      /    
  libpostproc       /   
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::: error: unknown type name ‘xvid_plugin_lumimasking_t’
     xvid_plugin_lumimasking_t masking_l       = {  }; /* For lumi masking */
     ^~~~~~~~~~~~~~~~~~~~~~~~~
libavcodec/libxvid.c::: error: unknown type name ‘xvid_plugin_lumimasking_t’
     xvid_plugin_lumimasking_t masking_v       = {  }; /* For variance AQ */
     ^~~~~~~~~~~~~~~~~~~~~~~~~
libavcodec/libxvid.c::: error: unknown type name ‘xvid_plugin_ssim_t’
     xvid_plugin_ssim_t        ssim            = {  };
     ^~~~~~~~~~~~~~~~~~
libavcodec/libxvid.c::: error: request for member ‘method’ in something not a structure or union
         masking_l.method                          = ;
                  ^
libavcodec/libxvid.c::: error: request for member ‘method’ in something not a structure or union
         masking_v.method                           = ;
                  ^
libavcodec/libxvid.c::: error: ‘xvid_plugin_ssim’ undeclared (first use in this function)
         plugins[xvid_enc_create.num_plugins].func  = xvid_plugin_ssim;
                                                      ^~~~~~~~~~~~~~~~
libavcodec/libxvid.c::: note: each undeclared identifier is reported only once for each function it appears in
libavcodec/libxvid.c::: error: request for member ‘b_printstat’ in something not a structure or union
         ssim.b_printstat                           = x->ssim == ;
             ^
libavcodec/libxvid.c::: error: request for member ‘acc’ in something not a structure or union
         ssim.acc                                   = x->ssim_acc;
             ^
libavcodec/libxvid.c::: error: request for member ‘cpu_flags’ in something not a structure or union
         ssim.cpu_flags                             = xvid_gbl_init.cpu_flags;
             ^
libavcodec/libxvid.c::: error: request for member ‘b_visualize’ in something not a structure or union
         ssim.b_visualize                           = ;
             ^
ffbuild/common.mak:: recipe for target 'libavcodec/libxvid.o' failed
make: *** [libavcodec/libxvid.o] Error 
           

那么你可以选择在编译ffmpeg的时候去掉”–enable-libxvid”的选项,也就是更改第六步为:

6.ffmpeg

ffmpeg-3.4.tar.bz2

下载地址:http://ffmpeg.org/

tar -zxvf ffmpeg-.tar.bz2
cd ffmpeg-
./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: undefined symbol: xvid_plugin_ssim
           

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

如果内容如下:

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

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

ldconfig
           

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

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

继续阅读