Build Your Own Video Community With Lighttpd And FlowPlayer (Debian Lenny) - Page 2
6 Configuring Lighttpd
Now we have to open lighttpd's main configuration file, /etc/lighttpd/lighttpd.conf, and add/enable the modules mod_secdownload and mod_flv_streaming in it. It is very important that mod_secdownload is listed before mod_flv_streaming in the server.modules stanza. When I did it the other way round, I found that fast-forwarding the video in FlowPlayer didn't work!
[...] server.modules = ( "mod_access", "mod_alias", "mod_accesslog", "mod_compress", # "mod_rewrite", # "mod_redirect", # "mod_evhost", # "mod_usertrack", # "mod_rrdtool", # "mod_webdav", # "mod_expire", "mod_secdownload", "mod_flv_streaming", # "mod_evasive" ) [...]
In the same file, we add also add the following configuration (you can add it right at the end of /etc/lighttpd/lighttpd.conf):
[...] flv-streaming.extensions = ( ".flv" ) secdownload.secret = "somesecret" secdownload.document-root = "/var/videos/flv/" secdownload.uri-prefix = "/dl/" secdownload.timeout = 120
Please replace somesecret with your own secret string (you can choose one).
What mod_secdownload does is this: a web application (e.g. a PHP script) can have a link in it of the following form:
where <token> is an MD5 of
- a secret string (user supplied)
- <rel-path> (starts with /)
mod_secdownload will then map this link to the appropriate file in the secdownload.document-root (which is outside the document root of the web site) and allow access to that file for secdownload.timeout seconds. After secdownload.timeout seconds, the link isn't valid anymore, and access is denied.
After we have installed FlowPlayer, we will use a PHP script to generate the appropriate video links for mod_secdownload.
You can find more information about mod_secdownload here: http://trac.lighttpd.net/trac/wiki/Docs%3AModSecDownload
Don't forget to restart lighttpd after your changes to /etc/lighttpd/lighttpd.conf:
7 Installing FlowPlayer
Go to http://flowplayer.org/download and download the latest FlowPlayer version to your /tmp directory, e.g. like this:
FlowPlayer comes in .zip format, so we must install unzip to uncompress it:
aptitude install unzip
Afterwards we can uncompress it:
This creates a directory called flowplayer in the /tmp directory. I'd like to have that directory in the document root of my video web site (/var/www), so I move it there:
mv flowplayer /var/www/
8 Configuring FlowPlayer
FlowPlayer is now installed, so all that is left to do is create an HTML file that lets us watch our video. I will create a PHP file for this called /var/www/flowplayertest.php which contains all parameters to start FlowPlayer in the user's browser and which also creates valid video links for mod_secdownload:
It's very important that $secret has the same value than secdownload.secret in /etc/lighttpd/lighttpd.conf. Also, $uri_prefix and secdownload.uri-prefix must match. If this is fulfilled, the above script will generate valid links. $f must hold the filename of the FLV video, beginning with a slash (/). (The filename is hard-coded in the above example, but of course you can program whatever you like to dynamically generate the filename.)
The important parts that call FlowPlayer are <script src="/flowplayer/example/flowplayer-3.1.4.min.js"></script> (which refers to the flowplayer-3.1.4.min.js script in the /var/www/flowplayer/example directory) in the <head></head> section and the following two parts in the <body></body> section:
href="<?php printf('%s%s/%s%s', $uri_prefix, $m, $t_hex, $f, $f); ?>"
(The most important setting is the href parameter (which is set by PHP in the above script) which specifies the path to the FLV video. In the style parameter, we can specify the width and height of our video player.)
(Here we specify the path to our FlowPlayer .swf file.)
This FlowPlayer configuration is taken from http://flowplayer.org/demos/installation/index.html.
To learn more about other ways of calling FlowPlayer and how to call it with specific settings, take a look at the examples on http://flowplayer.org/demos/index.html.
Now it's time to test our setup. Direct your browser to http://192.168.0.100/flowplayertest.php or http://server1.example.com/flowplayertest.php, and your video should start to play in your browser (including sound):
This is how the native Flash 9 full screen mode looks:
- 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/
- ffmpeg: http://ffmpeg.mplayerhq.hu/
- flvtool2: http://rubyforge.org/projects/flvtool2/
- PHP: http://www.php.net/
- Debian: http://www.debian.org/