I've been using the php pseudo-streaming plugin but this is way too bloated - why use the whole php env just to truncate a file and "echo" it at user. Try running empty .php file with just
<?php echo memory_get_usage(true) ?>
Now consider 200 people streaming 600 videos simultaneously. It could eat up your server's ram and cpu in no time :)Lighttpd has streaming built-in, apache doesn't. But I've dug out an apache module that does JUST that !
Apache flv streaming done right:
- Download my tuned version of mod_flvx or the original mod_flv by Paul Querna.
- Install apxs tool (also avaliable in RPMs for most systems as httpd-devel)
- Compile and install your module with the following command:
apxs -c -i ./mod_flvx.c - Add the following 2 lines to your httpd.conf or create a dedicated /etc/httpd/conf.d/mod_flvx.conf (path depends on your Linux distribution):
LoadModule flvx_module modules/mod_flvx.so AddHandler flv-stream .flv - Restart Apache (i.e. with service httpd restart)
Testing:
- Using curl:
..where 100000 is some byte position in your file. This should show you Content-Type: video/x-flv. Now increase the start= parameter and the Content-Length should be smaller accordingly.curl -I "http://mysite.com/video.flv?start=100000"
- Using wget:
The generated test.flv should be of size originalSize - 1MBwget -O test.flv "http://mysite.com/video.flv?start=1048576"
Notes
- To use with Flowplayer pseudo-streaming plugin, please setup your player as described here.
$f("lighty", "/swf/flowplayer-3.0.5.swf", { // configure clip to use "lighthttpd" plugin for providing video data clip: { url:'http://examples-s3.simplecdn.net/videos/Extremists.flv', provider: 'lighttpd' }, // streaming plugins are configured normally under plugins node plugins: { lighttpd: { url: 'flowplayer.pseudostreaming-3.0.3.swf' } } }); - Generated streams will work briliantly with Flowplayer, but you won't be able to play them back in standalone player (VLC, WMP etc.). So don't be suprised when you "wget" a video with ?start=1000 and the file doesn't play. That is because they don't have starting meta-data and players will have hard time deciding which codec to use.
- Streaming requires that your FLV has embedded keyframe markers (meta-data). You can inject any FLV with this data using flvtool2:
flvtool2 -U video.flv
More details on my blog:
http://tperspective.blogspot.com/2009/02/apache-flv-streaming-done-right.html
