FLV streaming using nginx and JW Player 5.1

FLV streaming using nginx and JW Player 5.1

debian, flash, nginx, server, video

Once, for some project I had a need to create small YouTube. Actually, ability to view video in the web providing skip forward and rewind ability. Especially such functionality is necessary when viewing long video in order not to wait until all video file is loaded.

Searching across Google how to make it work to skip forward and rewind – I was unable to find any reasonable advice, therefore, if you encounter with similar problem, please, take into account following rules:

1. Flv file should contain metadata! If you are using Adobe Video Encoder, such information is not added.
2. Initializing JW Player (using swfobject) in flashvars should be assigned provider=http;

 

About FLV.

With a growing popularity of Flash, video standard – flv comes with it. Format is rather young and was first introduced with Flash version 7, and accordingly to Wikipedia was launched at 2003. I can imagine, at the time, when Flash had not gained large popularity, how unwillingly users updated flash players to newer ones. Thus, that would not be true to say that flv video format was known in 2003. Now – it is!

Outside FLV there some alternatives exists:

1. Play video from server as file. As a result, user had to wait until file is downloaded before it will be available for playback. Video player issue is up to users. And, of course, good question – what codec to use to code video.

2. Video can be encoded in some of container-type format, like wmv, mov. Benefit – video can be started to playback before it is completely downloaded. Weakness -  it is impossible to predict which and if any player is installed on client computers (remember the war between Mac and MS platforms).

3. Involve media server. All tries to find open source server or for reasonable price – did not succeeded. It might be also inconvenient to add media file.

Installation

If you are using shared hosting – you can’t read feather, because described tutorial require some more rights. But, fortunately, exists pseudo streaming, and all you will need is php. No server configuration. But for server side streaming you will need Nginx.

My configuration:

1. Apache2 running on port 8080, where php (or ruby) is serverd.
2. Nginx working on port 80 and is a aproxy forwarding all requests to port 8080. More read here [2]

Nginx configuration:

server {

  listen 80;

  server_name video.mydomain.tld;

  access_log /var/log/nginx/video.access.log;

  location ~ \.flv$ {
    flv;
    root /var/www;
  }

  location / {
    root /var/www;
    index index.html index.htm;
  }

}

3. Let us encode video to flv. In linux: ffmpeg -i "01.avi" -y -f flv -ar 44100 "movie.flv"
4.  Let us add flv metadata. Can be done with multiple tools. For example this-  [5].
Linux environment: flvtool2 -UP movie.flv
5. Fetch JW Player. Here [3].
6. Prepare web page:

<div id="flashContent"></div>

<script type="text/javascript">
  var so = new SWFObject('player.swf','flashContent','720','576','9');
  so.addParam('allowfullscreen','true');
  so.addParam('allowscriptaccess','always');
  so.addParam('bgcolor','#FFFFFF');
  so.addParam("flashvars","file=movie.flv&provider=http");
  so.write('flashContent');
</script>

assuming index.html is located at the same folder as vide.

After these steps everything should work! :)

 

Skipping forward (rewind) in nginx logs we should look something like this:

"GET /movie.flv?start=27503944 HTTP/1.1" 200 1752013
"GET /movie.flv?start=88336188 HTTP/1.1" 200 13564873

If something does not work:

- If you see in logs at movie.flv error 404 – incorrect root configuration in nginx.conf.
- If player does not allow to jump forward and in nginx logs you see records without start attribute – flv metadata are missing or not created.

 

[1] http://developer.longtailvideo.com/trac/wiki/Player5Formats
[2] http://kovyrin.net/2006/05/18/nginx-as-reverse-proxy/
[3] http://www.longtailvideo.com/players/jw-flv-player/
[4] http://stream.xmoov.com/
[5] http://www.buraks.com/flvmdi/

» Rate it!

(29)

» Related articles

» Comments

No comments
* mandatory
* not public
Besucherzahler ukraina brides
website counter
vimeo youtube     myspace facebook twitter
where to eat in riga?