<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>超群.com的博客 &#187; linux</title>
	<atom:link href="http://www.fuchaoqun.com/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fuchaoqun.com</link>
	<description></description>
	<lastBuildDate>Thu, 08 Sep 2011 15:08:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>ffmpeg-php在CentOS上的快速安装</title>
		<link>http://www.fuchaoqun.com/2008/07/ffmpeg-php-install-on-centos/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ffmpeg-php-install-on-centos</link>
		<comments>http://www.fuchaoqun.com/2008/07/ffmpeg-php-install-on-centos/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 02:20:11 +0000</pubDate>
		<dc:creator>超群.com</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[默认分类]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[ffmpeg-php]]></category>
		<category><![CDATA[linux]]></category>
		<guid isPermaLink="false">http://chaoqun.17348.com/?p=1</guid>
		<description><![CDATA[本博客所有原创文章采用知识共享署名-非商业性使用-相同方式共享，转载请保留链接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&#38;ffmpeg-php yum install ffmpeg ffmpeg-devel 没有找到ffmpeg-php的安装包，所以只能编译安装了，下面是编译步骤： wget [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>本博客所有原创文章采用<a href="http://creativecommons.org/licenses/by-nc-sa/2.5/cn/" target="_blank">知识共享署名-非商业性使用-相同方式共享</a>，转载请保留链接<a href="http://chaoqun.17348.com/2008/07/ffmpeg-php-install-on-centos">http://chaoqun.17348.com/2008/07/ffmpeg-php-install-on-centos</a></p></blockquote>
<p>最近的一个项目，要批量获取音频文件（包括mp3、wma等格式）的播放时长，由于项目整体是Lamp结构的，所以最佳的方案就是能找到这么一个PHP扩展能提供这样的功能接口。</p>
<p>我们用到的开源项目是<a href="http://ffmpeg-php.sourceforge.net/">http://ffmpeg-php.sourceforge.net/</a>，ffmpeg的php扩展，下面是ffmpeg-php在linux下的快速安装。</p>
<p>安装需求：</p>
<li><a href="http://ffmpeg.sourceforge.net/index.php">ffmpeg</a>-0.4.9_pre1 or higher.</li>
<li><a href="http://www.php.net/">php</a>-4.3.0 or higher *需要有php-dev包，如果服务器上没有，可以通过yum install php-dev进行安装</li>
<li><a href="http://www.boutell.com/gd/">gd</a>-2.0 or higher (the version of GD bundled with PHP works too) *这个一般都有吧</li>
<p>编译安装ffmpeg非常的麻烦，还好我们找到了一个yum源可以方便的安装ffmpeg以及ffmpeg-dev，下面是步骤：</p>
<p>vi /etc/yum.repos.d/dag.repo</p>
<p>输入：</p>
<p>[dag]<br />
name=Dag RPM Repository for Red Hat Enterprise Linux<br />
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag<br />
gpgcheck=1<br />
enabled=1</p>
<p>导入Dag的RPM_GPG_KEY,否则提示没有key无法安装</p>
<p>wget <a href="http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt">http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt</a><br />
rpm -import RPM-GPG-KEY.dag.txt</p>
<p>安装ffmpeg&amp;ffmpeg-php</p>
<p>yum install ffmpeg ffmpeg-devel</p>
<p>没有找到ffmpeg-php的安装包，所以只能编译安装了，下面是编译步骤：</p>
<p>wget <a href="http://internap.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.5.1.tbz2">http://internap.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.5.1.tbz2</a><a href="http://nchc.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.5.3.1.tbz2"></a><br />
tar -xjf ffmpeg-php-0.5.1.tbz2<br />
phpize<br />
./configure<br />
make &amp;&amp; make install</p>
<p>安装完之后，把ffmpeg.so（我的位置是/usr/local/lib/php/extensions/no-debug-non-zts-20060613/） 复制到php的扩展目录下，在php.ini中加入</p>
<p>extension=ffmpeg</p>
<p>ffmpeg-php的api参考<a href="http://ffmpeg-php.sourceforge.net/doc/api/">http://ffmpeg-php.sourceforge.net/doc/api/</a></p>
<p>写了一个简单调用程序</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// 获得音频文件时长</span>
<span style="color: #000000; font-weight: bold;">function</span> get_audio_time<span style="color: #009900;">&#40;</span><span style="color: #000088;">$audio_file</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$audio</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ffmpeg_movie<span style="color: #009900;">&#40;</span><span style="color: #000088;">$audio_file</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$audio</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDuration</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//遍历目录下所有文件</span>
<span style="color: #000000; font-weight: bold;">function</span> get_audio_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir_path</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    static <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$tmp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">glob</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir_path</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/*'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tmp</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            get_audio_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$path</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$file_array</span> <span style="color: #339933;">=</span> get_audio_file<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'audios'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    get_audio_time<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>
<p>在audios目录下放了三首mp3歌曲，用ab简单测试了一下结果（测试机配置巨差），下面是测试结果，处理结果大概是80首/s，还是可以接受的。</p>
<p>[root@centos ffmpeg]# ab -n 5000 -c 100 <a href="http://*****/ffmpeg/mp3timer.php">http://*****/ffmpeg/mp3timer.php</a><br />
This is ApacheBench, Version 2.0.41-dev &lt;$Revision: 1.141 $&gt; apache-2.0<br />
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, <a href="http://www.zeustech.net/">http://www.zeustech.net/</a><br />
Copyright (c) 1998-2002 The Apache Software Foundation, <a href="http://www.apache.org/">http://www.apache.org/</a><br />
Benchmarking 10.210.70.52 (be patient)<br />
Completed 500 requests<br />
Completed 1000 requests<br />
Completed 1500 requests<br />
Completed 2000 requests<br />
Completed 2500 requests<br />
Completed 3000 requests<br />
Completed 3500 requests<br />
Completed 4000 requests<br />
Completed 4500 requests<br />
Finished 5000 requests<br />
Server Software:        Apache/2.2.0<br />
Server Hostname:        10.210.70.52<br />
Server Port:            80<br />
Document Path:          /ffmpeg/mp3timer.php<br />
Document Length:        0 bytes<br />
Concurrency Level:      100<br />
Time taken for tests:   189.695710 seconds<br />
Complete requests:      5000<br />
Failed requests:        0<br />
Write errors:           0<br />
Total transferred:      1070176 bytes<br />
HTML transferred:       0 bytes<br />
Requests per second:    26.36 [#/sec] (mean)<br />
Time per request:       3793.914 [ms] (mean)<br />
Time per request:       37.939 [ms] (mean, across all concurrent requests)<br />
Transfer rate:          5.51 [Kbytes/sec] received<br />
Connection Times (ms)<br />
              min  mean[+/-sd] median   max<br />
Connect:        0    1   9.7      0     111<br />
Processing:    14 3411 6589.3    765   69462<br />
Waiting:       13 2964 5046.4    759   56432<br />
Total:         14 3412 6589.3    765   69462<br />
Percentage of the requests served within a certain time (ms)<br />
  50%    765<br />
  66%   1104<br />
  75%   3052<br />
  80%   5657<br />
  90%  11060<br />
  95%  14409<br />
  98%  24880<br />
  99%  38720<br />
 100%  69462 (longest request)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fuchaoqun.com/2008/07/ffmpeg-php-install-on-centos/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
