PHP完全自学手册(珍藏版) 中文pdf扫描版下载
最近在做视频模块,要求获取视频的相关信息,比如视频的时长,分辨率的长宽,还有就是视频帧数还有截图等,通过查找资料,最佳的方案就是安装ffmpeg-php这个PHP扩展能提供这样的功能接口。
操作系统:CentOS 6.2 minimal
由于默认的CentOS的软件仓库里没有FFmpeg、FFmpeg-PHP,所以安装第三方的软件仓库。
安装顺序:
- 资料参考:
- http://wiki.mediatemple.net/w/(dv):Installing_FFmpeg_and_FFmpeg-php
- http://www.mysql-apache-php.com/ffmpeg-install.htm
- #svn源地址
- https://ffmpeg-php.svn.sourceforge.net/svnroot/ffmpeg-php
- #可使用软件版本:ffmpeg-php-0.6.1 分支:/branches/ffmpeg-php/ffmpeg-php-0.6.1
- #最新版本:ffmpeg-php-0.7.1 trunk/ffmpeg-php 编译报错 不可用
安装ffmpeg ffmpeg-devel
- 1.ffmpeg
- 2.ffmpeg-devel
- 3.ffmpeg-php
操作系统:CentOS 6.2 minimal
由于默认的CentOS的软件仓库里没有FFmpeg、FFmpeg-PHP,所以安装第三方的软件仓库。
安装php-ffmpeg
- 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
- #gpgcheck 默认为0即可!设置gpgcheck=1会让yum检查每个下载的RPM的GnuPG签名。这么做是因为你需要适当的GnuPG key注册到您的RPM数据库。可以防止被欺骗.
- #安装 Install ffmpeg 等模块
- yum -y install ffmpeg ffmpeg-devel
- #下载地址
- 这个安装错误己修复 可以正常安装
- wget http://img.kuitao8.com/uploads/2015/0916/20150916100916263.zip
- unzip 20150916100916263.zip
- tar zxvf **.tar
- cd 目录
- 首先make clean下
- 再运行
- /usr/local/php/bin/phpize
- ./configure --with-php-config=/usr/local/php/bin/php-config --enable-skip-gd-check &make
下一步
- make install
- //然后
- echo "extension=ffmpeg.so" >> /usr/local/php/etc/php.ini
- //重启
- service php-fpm restart
安装成功
测试
- <?php
- $movefile = "./4.mp4";
- $mov = new ffmpeg_movie($movefile);
- printf("file name = %s\n", $mov->getFileName());
- printf("duration = %s seconds\n", $mov->getDuration());
- printf("frame count = %s\n", $mov->getFrameCount());
- printf("frame rate = %0.3f fps\n", $mov->getFrameRate());
- printf("comment = %s\n", $mov->getComment());
- printf("title = %s\n", $mov->getTitle());
- printf("author = %s\n", $mov->getAuthor());
- printf("copyright = %s\n", $mov->getCopyright());
- printf("get bit rate = %d\n", $mov->getBitRate());
- printf("has audio = %s\n", $mov->hasAudio() == 0 ? 'No' : 'Yes');
- if ($mov->hasAudio()) {
- printf("get audio stream id= %s\n", $mov->getAudioStreamId());
- printf("get audio codec = %s\n", $mov->getAudioCodec());
- printf("get audio bit rate = %d\n", $mov->getAudioBitRate());
- printf("get audio sample rate = %d \n", $mov->getAudioSampleRate());
- printf("get audio channels = %s\n", $mov->getAudioChannels());
- }
- printf("has video = %s\n", $mov->hasVideo() == 0 ? 'No' : 'Yes');
- if ($mov->hasVideo()) {
- printf("frame height = %d pixels\n", $mov->getFrameHeight());
- printf("frame width = %d pixels\n", $mov->getFrameWidth());
- printf("get video stream id= %s\n", $mov->getVideoStreamId());
- printf("get video codec = %s\n", $mov->getVideoCodec());
- printf("get video bit rate = %d\n", $mov->getVideoBitRate());
- printf("get pixel format = %s\n", $mov->getPixelFormat());
- printf("get pixel aspect ratio = %s\n", $mov->getPixelAspectRatio());
- $frame = $mov->getFrame(10);
- printf("get frame = %s\n", is_object($frame) ? 'true' : 'false');
- printf(" get frame number = %d\n", $mov->getFrameNumber());
- printf(" get frame width = %d\n", $frame->getWidth());
- printf(" get frame height = %d\n", $frame->getHeight());
- }
- echo "\n--------------------\n\n";
转载请注明:谷谷点程序 » php利用安装ffmpeg-php扩展来获取对视频信息操作