RH linux+ lighttpd+php5+ffmpeg+flvtool2
begin Build Your Own Video Community
一、为了能够正确安装lighttpd,需要先安装PCRE
**************************************
*PCRE
**************************************
http://www.pcre.org/
二、安装lighttpd
**************************************
*lighttpd
**************************************
1.Compiling from Source
$ gzip -cd lighttpd-1.3.15.tar.gz | tar xf -
$ cd lighttpd-1.4.11
$ ./configure
$ make
$ make install
2.init scripts :
$ sed -e 's/FOO/lighttpd/g' doc/rc.lighttpd.redhat > /etc/init.d/lighttpd
$ chmod a+rx /etc/init.d/lighttpd
$ cp -p doc/sysconfig.lighttpd /etc/sysconfig/lighttpd
$ install -Dp ./doc/lighttpd.conf /etc/lighttpd/lighttpd.conf
$ chkconfig lighttpd on
3.up/down:
/etc/init.d/lighttpd start
/etc/init.d/lighttpd stop
或者
/etc/init.d/lighttpd start
/etc/init.d/lighttpd stop
4.config file:
/etc/lighttpd/lighttpd.conf
server.document-root = "/www/pages/"
server.port = 81
注意:最好为lighttpd建立一个专门的用户。
5.check config file:
$ lighttpd -t -f /etc/lighttpd/lighttpd.conf
6.start the server:
$ lighttpd -D -f /etc/lighttpd/lighttpd.conf
注意请先建立/www目录。并且制定合适的权限。
7.log file:
/www/logs/access.log
/www/logs/lighttpd.error.log
安装过程中遇到问题,可以参考这个文档。
http://trac.lighttpd.net/trac/wiki/TutorialInstallation
三、安装php5
**************************************
*php5
**************************************
install:
gunzip php-xxx.tar.gz
tar -xvf php-xxx.tar
$ ./configure --enable-fastcgi --enable-discard-path --enable-force-cgi-redirect
modify your php.ini:
cgi.fix_pathinfo=1
modify your lighttpd.conf:
1.server.modules = (
"mod_fastcgi",
)
2.fastcgi.server = ( ".php" => ((
"bin-path" => "/path/to/php-cgi",
"socket" => "/tmp/php.socket"
)))
四、安装LAME 和 ffmpeg
**************************************
*LAME
**************************************
installing:
gunzip lame-3.97.tar.gz
tar -xvf lame-3.97.tar
./configure --enable-shared --prefix=/usr
...
**************************************
*ffmpeg
**************************************
installing:
五、安装Ruby 和 flvtool2
**************************************
*Ruby
**************************************
installing:
gunzip ruby-1.8.6-p110.tar.gz
tar -xvf ruby-1.8.6-p110.tar
./configure
make
make install
**************************************
*flvtool2
**************************************
installing:
gunzip flvtool2-1.0.6.tgz
tar -xvf flvtool2-1.0.6.tgz
ruby setup.rb config
ruby setup.rb setup
sudo ruby setup.rb install
六、创建视频,转换成FLV格式
**************************************
*Creating Video Directories
**************************************
mkdir -p /var/videos/incoming
mkdir -p /var/videos/flv
**************************************
*Encoding Videos To FLV
**************************************
source:avi,mp4,mov,mpg,3gp,mpeg,vmv
ffmpeg -i /var/videos/incoming/video.avi -s 320x240 -ar 44100 -r 12 /var/videos/flv/video.flv
add metadata to video.flv with flvtool2:
cat /var/videos/flv/video.flv | flvtool2 -U stdin /var/videos/flv/video.flv
or
/usr/local/bin/flvtool2 -UP 9.flv
七、配置lighttpd
**************************************
*Configuring Lighttpd
**************************************
1.modify /etc/lighttpd/lighttpd.conf
server.modules = (
"mod_secdownload",
"mod_flv_streaming",
)
end:
flv-streaming.extensions = ( ".flv" )
secdownload.secret = "somesecret"
secdownload.document-root = "/var/videos/flv/"
secdownload.uri-prefix = "/dl/"
secdownload.timeout = 120
2.restart lighttpd
八、安装播放器FlowPlayer
**************************************
*FlowPlayer
**************************************
mv flowplayer /www/pages/
九、编辑测试页并运行
<?php
//一下要和lighttpd的配置文件一致
$secret = "123456";
$uri_prefix = "/dl/";
# filename
$f = "/9.flv";
# current timestamp
$t = time();
$t_hex = sprintf("%08x", $t);
$m = md5($secret.$f.$t_hex);
?>
<html>
<head>
<title>Flowplayer Test</title>
</head>
<body text="#000000" bgcolor="#FFFFFF" link="#FF0000" alink="#FF0000" vlink="#FF0000">
<object type="application/x-shockwave-flash" data="/flowplayer/FlowPlayerBlack.swf"
width="320" height="256" id="FlowPlayer">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="/flowplayer/FlowPlayerBlack.swf" />
<param name="quality" value="high" />
<param name="scale" value="noScale" />
<param name="allowFullScreen" value="true" />
<param name="flashvars" value="config={videoFile: '<?php printf('%s%s/%s%s', $uri_prefix, $m, $t_hex, $f, $f); ?>', streamingServer: 'lighttpd', loop: 'false', useNativeFullScreen: true}" />
</object>
</body>
</html>
-----------------------------------------------------------------------
Links:
-----------------------------------------------------------------------
* Lighttpd: http://www.lighttpd.net
* mod_flv_streaming: http://blog.lighttpd.net/articles/2006/03/09/flv-streaming-with-lighttpd
* mod_secdownload: http://trac.lighttpd.net/trac/wiki/Docs%3AModSecDownload
* FlowPlayer: http://flowplayer.org
* LAME: http://lame.sourceforge.net
* ffmpeg: http://ffmpeg.mplayerhq.hu
* flvtool2: http://rubyforge.org/projects/flvtool2
* PHP: http://www.php.net
参考资料:
1.Build Your Own Video Community With Lighttpd And FlowPlayer (Debian Etch)
http://www.howtoforge.com/video_streaming_lighttpd_flowplayer
2.Using Lighttpd, Mplayer/Mencoder and Flvtool2 to Implement Flash Video Streaming :: Homo-Adminus Blog by Alexey Kovyrin
http://www.clipclip.org/yaoweizhen?page=4
-----------------------------------------------------------------------
备注:
-----------------------------------------------------------------------
打开端口的命令:
iptables -A INPUT -d 目的地址 -p tcp -m tcp --dport 81 -j ACCEPT
/etc/sysconfig/iptables 文件是 iptables 守护进程调用的默认规则集文件.
可以使用以下命令保存执行过的IPTABLES命令:
/sbin/iptables-save > /etc/sysconfig/iptables
参考iptables
http://zhidao.baidu.com/question/37749857.html