Skip to content

Instantly share code, notes, and snippets.

@chappyhome
Created March 4, 2014 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save chappyhome/9339246 to your computer and use it in GitHub Desktop.
Save chappyhome/9339246 to your computer and use it in GitHub Desktop.
ffmpeg-php在CentOS上的快速安装
ffmpeg-php在CentOS上的快速安装
3 Replies
本博客所有原创文章采用知识共享署名-非商业性使用-相同方式共享,转载请保留链接http://chaoqun.17348.com/2008/07/ffmpeg-php-install-on-centos
最近的一个项目,要批量获取音频文件(包括mp3、wma等格式)的播放时长,由于项目整体是Lamp结构的,所以最佳的方案就是能找到这么一个PHP扩展能提供这样的功能接口。
我们用到的开源项目是http://ffmpeg-php.sourceforge.net/,ffmpeg的php扩展,下面是ffmpeg-php在linux下的快速安装。
安装需求:
ffmpeg-0.4.9_pre1 or higher.
php-4.3.0 or higher *需要有php-dev包,如果服务器上没有,可以通过yum install php-dev进行安装
gd-2.0 or higher (the version of GD bundled with PHP works too) *这个一般都有吧
编译安装ffmpeg非常的麻烦,还好我们找到了一个yum源可以方便的安装ffmpeg以及ffmpeg-dev,下面是步骤:
vi /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=1
enabled=1
导入Dag的RPM_GPG_KEY,否则提示没有key无法安装
wget http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt
rpm -import RPM-GPG-KEY.dag.txt
安装ffmpeg&ffmpeg-php
yum install ffmpeg ffmpeg-devel
没有找到ffmpeg-php的安装包,所以只能编译安装了,下面是编译步骤:
wget http://internap.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.5.1.tbz2
tar -xjf ffmpeg-php-0.5.1.tbz2
phpize
./configure
make && make install
安装完之后,把ffmpeg.so(我的位置是/usr/local/lib/php/extensions/no-debug-non-zts-20060613/) 复制到php的扩展目录下,在php.ini中加入
extension=ffmpeg
ffmpeg-php的api参考http://ffmpeg-php.sourceforge.net/doc/api/
写了一个简单调用程序
<?php
// 获得音频文件时长
function get_audio_time($audio_file)
{
$audio = new ffmpeg_movie($audio_file, false);
return $audio->getDuration();
}
//遍历目录下所有文件
function get_audio_file($dir_path)
{
static $file;
$tmp = glob($dir_path . '/*');
foreach ($tmp as $path)
{
if (is_dir($path))
{
get_audio_file($path);
}else
{
$file[] = $path;
}
}
return $file;
}
$file_array = get_audio_file('audios');
foreach ($file_array as $file)
{
get_audio_time($file);
}
?>
在audios目录下放了三首mp3歌曲,用ab简单测试了一下结果(测试机配置巨差),下面是测试结果,处理结果大概是80首/s,还是可以接受的。
[root@centos ffmpeg]# ab -n 5000 -c 100 http://*****/ffmpeg/mp3timer.php
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/
Benchmarking 10.210.70.52 (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Finished 5000 requests
Server Software: Apache/2.2.0
Server Hostname: 10.210.70.52
Server Port: 80
Document Path: /ffmpeg/mp3timer.php
Document Length: 0 bytes
Concurrency Level: 100
Time taken for tests: 189.695710 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 1070176 bytes
HTML transferred: 0 bytes
Requests per second: 26.36 [#/sec] (mean)
Time per request: 3793.914 [ms] (mean)
Time per request: 37.939 [ms] (mean, across all concurrent requests)
Transfer rate: 5.51 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 9.7 0 111
Processing: 14 3411 6589.3 765 69462
Waiting: 13 2964 5046.4 759 56432
Total: 14 3412 6589.3 765 69462
Percentage of the requests served within a certain time (ms)
50% 765
66% 1104
75% 3052
80% 5657
90% 11060
95% 14409
98% 24880
99% 38720
100% 69462 (longest request)
This entry was posted in PHP, 默认分类 and tagged centos, ffmpeg-php, linux on 07/31/2008 by 超
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment