一、yum安装ffmpeg

1、添加yum源:

vim/etc/yum.repos.d/dag.repo[dag]name=DagRPMRepositoryforRedHatEnterpriseLinuxbaseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/daggpgcheck=0enabled=1

2、安装

yum-yinstallffmpeg

yum安装FFmpeg比源码编译安装省时省力,但缺点也很明显,版本过老,为0.6.5版,最新版已为2.8,新旧版很多参数有所差异,旧版支持的格式也没有新版丰富。编译安装太麻烦,安装比较复杂。


二、ffmpeg使用

1、压缩视频

ffmmpeg-i$videoFilename-strict-2-vcodeclibx264-vprelibx264-default-vbstreamCode$newFilename

其中streamCode为转换后的码流。比如 1024K。

例:

ffmpeg-ilol.mp4-strict-2-vcodeclibx264-vprelibx264-default-vb512Klol_1.mp4

不加-vpre libx264-default会报错,错误内容:

[libx264 @ 0x1bef570]use an encoding preset (e.g. -vpre medium)

[libx264 @ 0x1bef570]preset usage: -vpre <speed> -vpre <profile>

[libx264 @ 0x1bef570]speed presets are listed in x264 --help

[libx264 @ 0x1bef570]profile is optional; x264 defaults to high

需要指定配置文件,在/usr/share/ffmpeg目录下有许多的配置文件。根据需要调用不同的就好。配置文件是以.ffpreset结尾的,加参数时不需要加这个后缀名。

2、截取视频中缩略图

ffmmpeg-y-i$mp4FileName-vframes1-ss秒数-fmjpeg-s1280*640-an$thumbFileName

例:

ffmpeg-y-ilol.mp4-vframes1-ss16-fmjpeg-s1280*640-anlol.jpg

3、视频转MP3

ffmpeg-i$videoFilename-vn-ar44100-ac2-ab192-fmp3$audioFilename

例:

ffmpeg-ilol.mp4-vn-ar44100-ac2-ab192-fmp3lol.mp3

三、ffmpeg-php扩展安装

1、安装ffmpeg-devel

yum-yinstallffmpeg-devel

2、编译安装ffmpeg-php

tarjxvfffmpeg-php-0.6.2.tbz2cdffmpeg-php-0.6.2/usr/local/php/bin/phpize./configure--with-php-config=/usr/local/php/bin/php-config--with-ffmpegmake&&makeinstall

./configure --with-php-config=/usr/local/php/bin/php-config --with-ffmpeg --enable-skip-gd-check 加上--enable-skip-gd-check在phpinfo中查看ffmpeg-php gd support会是enabled不加的话disabled。

报错信息:

/root/ffmpeg-php-0.6.2/ffmpeg_movie.c: 在函数‘zim_ffmpeg_movie___construct’中:

/root/ffmpeg-php-0.6.2/ffmpeg_movie.c:312: 错误:‘list_entry’未声明(在此函数内第一次使用)

/root/ffmpeg-php-0.6.2/ffmpeg_movie.c:312: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其

/root/ffmpeg-php-0.6.2/ffmpeg_movie.c:312: 错误:所在的函数内也只报告一次。)

/root/ffmpeg-php-0.6.2/ffmpeg_movie.c:312: 错误:‘le’未声明(在此函数内第一次使用)

/root/ffmpeg-php-0.6.2/ffmpeg_movie.c:347: 错误:expected ‘;’ before ‘new_le’

/root/ffmpeg-php-0.6.2/ffmpeg_movie.c:357: 错误:‘new_le’未声明(在此函数内第一次使用)

/root/ffmpeg-php-0.6.2/ffmpeg_movie.c: 在函数‘_php_read_av_frame’中:

/root/ffmpeg-php-0.6.2/ffmpeg_movie.c:1216: 警告:不建议使用‘avcodec_decode_video’(声明于 /usr/include/libavcodec/avcodec.h:3452)

make: *** [ffmpeg_movie.lo] 错误 1

解决错误:

vim/root/ffmpeg-php-0.6.2/ffmpeg_movie.crow312:list_entry*le;改为zend_rsrc_list_entry*le;row347:list_entrynew_le;改为zend_rsrc_list_entrynew_le;row361:hashkey_length+1,(void*)&new_le,sizeof(list_entry),改为hashkey_length+1,(void*)&new_le,sizeof(zend_rsrc_list_entry),

然后重新make提示make test,

maketest

报错信息:

+-----------------------------------------------------------+

| ! ERROR ! |

| The test-suite requires that proc_open() is available. |

| Please check if you disabled it in php.ini. |

+-----------------------------------------------------------+

解决错误:

编辑php.ini文件,找到disable_functions去掉proc_open。

然后在make test,make install

Doyouwanttosendthisreportnow?[Yns]:N选择N

3、在php.ini中加入扩展

sed-i'/thedl()/iextension="ffmpeg.so"'/usr/local/php/etc/php.ini

4、验证

在phpinfo.php中查看是否有了ffmpeg-php。

直接输入ffmpeg查看ffmpeg一些信息

ffmpegFFmpegversion0.6.5,Copyright(c)2000-2010theFFmpegdevelopersbuiltonJan29201217:52:15withgcc4.4.520110214(RedHat4.4.5-6)configuration:--prefix=/usr--libdir=/usr/lib64--shlibdir=/usr/lib64--mandir=/usr/share/man--incdir=/usr/RCE=2-fexceptions-fstack-protector--param=ssp-buffer-size=4-m64-mtune=generic-fPIC'--enable-avfilter--ele-libfaad--enable-libfaadbin--enable-libgsm--enable-libmp3lame--enable-libopencore-amrnb--enable-libopencibtheora--enable-libx264--enable-gpl--enable-nonfree--enable-postproc--enable-pthreads--enable-shared--elibavutil50.15.1/50.15.1libavcodec52.72.2/52.72.2libavformat52.64.2/52.64.2libavdevice52.2.0/52.2.0libavfilter1.19.0/1.19.0libswscale0.11.0/0.11.0libpostproc51.2.0/51.2.0HyperfastAudioandVideoencoderusage:ffmpeg[options][[infileoptions]-iinfile]...{[outfileoptions]outfile}...Use-htogetfullhelpor,evenbetter,run'manffmpeg'