I have a video streaming site with the following lighttpd configuration:
server.modules = (
"mod_compress",
"mod_access",
"mod_alias",
"mod_rewrite",
"mod_redirect",
"mod_secdownload",
"mod_h264_streaming",
"mod_flv_streaming",
"mod_accesslog",
"mod_auth",
"mod_status",
"mod_expire",
"mod_fastcgi"
)
server.document-root = "/data/domain.com/"
index-file.names = ( "index.html" )
server.tag = "xhttpd"
url.access-deny = ( "~", ".inc" )
dir-listing.encoding = "utf-8"
mimetype.assign = (
".gif" => "image/gif",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".css" => "text/css",
".html" => "text/html; charset=UTF-8",
".htm" => "text/html; charset=UTF-8",
".js" => "text/javascript",
".mp4" => "video/mp4",
".3gp" => "video/3gpp",
".3gpp" => "video/3gpp",
# make the default mime type application/octet-stream.
"" => "application/octet-stream",
)
mimetype.use-xattr = "enable"
server.port = 80
server.pid-file = "/var/run/lighttpd.pid"
server.username = "nginx"
server.groupname = "nginx"
server.stat-cache-engine = "simple" # either fam, simple or disabled
# see http://blog.lighttpd.net/articles/2005/11/11/optimizing-lighty-for-high-concurrent-large-file-downloads
server.network-backend = "writev"
# http://redmine.lighttpd.net/wiki/1/Server.event-handlerDetails
server.event-handler = "linux-sysepoll"
server.max-fds = 8192
server.max-connections = 2048
server.max-write-idle = 360
server.max-keep-alive-requests = 4
server.max-keep-alive-idle = 4
server.max-read-idle = 30
# Files ending in .flv and .3gp are served by the module
h264-streaming.extensions = (".mp4" )
$HTTP["url"] =~ "mp4$" {
connection.kbytes-per-second = 90
}
# Add Expires/Cache-Control header
$HTTP["url"] =~ "\.(mp4|3gp|flv)$" {
expire.url = ( "" => "access 8 hours" )
}
The player is jwplayer, and all my videos are mp4 with metadata set at the begining at the file using mp4box. Lighttpd is patched with h264 codeshop code.
Unfortunately, while the streaming and seeking work perfectly, there is a big difference in the starting time of videos.
For short videos (2-5 minutes), it starts playing immediately. For Long videos (20 to 60 minutes), it can take minutes before starting playing which make leave the user since he believes the video is not working.
Why does this happen, and above all, how to avoid it?