温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ffmpeg安装使用及ffmpeg-php安装

发布时间:2020-06-08 07:28:03 来源:网络 阅读:5533 作者:铁刚 栏目:web开发

一、yum安装ffmpeg

1、添加yum源:

vim /etc/yum.repos.d/dag.repo
[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=0
enabled=1

2、安装

yum -y install ffmpeg

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


二、ffmpeg使用

1、压缩视频

ffmmpeg -i $videoFilename -strict -2 -vcodec libx264  -vpre libx264-default -vb streamCode $newFilename

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

例:

ffmpeg -i lol.mp4 -strict -2 -vcodec libx264 -vpre libx264-default -vb 512K lol_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 -vframes 1 -ss 秒数 -f mjpeg -s 1280*640 -an $thumbFileName

例:

ffmpeg -y -i lol.mp4 -vframes 1 -ss 16 -f mjpeg -s 1280*640 -an lol.jpg

3、视频转MP3

ffmpeg -i $videoFilename -vn -ar 44100 -ac 2 -ab 192 -f mp3 $audioFilename

例:

ffmpeg -i lol.mp4 -vn -ar 44100 -ac 2 -ab 192 -f mp3 lol.mp3

三、ffmpeg-php扩展安装

1、安装ffmpeg-devel

yum -y install ffmpeg-devel

2、编译安装ffmpeg-php

tar jxvf ffmpeg-php-0.6.2.tbz2
cd ffmpeg-php-0.6.2
/usr/local/php/bin/phpize 
./configure --with-php-config=/usr/local/php/bin/php-config --with-ffmpeg
make && make install

./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.c
row 312: list_entry *le; 改为zend_rsrc_list_entry *le;
row 347: list_entry new_le;改为 zend_rsrc_list_entry new_le;
row 361: hashkey_length+1, (void *)&new_le, sizeof(list_entry),改为hashkey_length+1, (void *)&new_le,sizeof(zend_rsrc_list_entry),

然后重新make提示make test,

make test

报错信息:

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

|                       ! 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

Do you want to send this report now? [Yns]: N     选择N

3、在php.ini中加入扩展

sed -i '/the dl()/i extension = "ffmpeg.so"' /usr/local/php/etc/php.ini

4、验证

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

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

ffmpeg
FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers
  built on Jan 29 2012 17:52:15 with gcc 4.4.5 20110214 (Red Hat 4.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 --e
  libavutil     50.15. 1 / 50.15. 1
  libavcodec    52.72. 2 / 52.72. 2
  libavformat   52.64. 2 / 52.64. 2
  libavdevice   52. 2. 0 / 52. 2. 0
  libavfilter    1.19. 0 /  1.19. 0
  libswscale     0.11. 0 /  0.11. 0
  libpostproc   51. 2. 0 / 51. 2. 0
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'




向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI