You can see final result of this tutorial @ wovi.es

Mod_h264

This mod runs the show. It enable your viewers to immediately jump to any part of the video regardless of the length of the video or whether it has all been downloaded yet. It also gives you possibility to only playback a part of the video or create download links to specific parts of the video. This opens door for an easy way for making previews available, say for example when you want to differentiate between registered and unregistered users, but more on this when we deal with mod_auth_token which will protect full length movies from being watched by unregistered users.

Instructions for CentOS

Find LoadModule and at the end add:

Mod_auth_token

mod_auth_token is a cool apache module that allow you to generate URIS for a determined time window, you can also limit them by IP (IP limit available only in 1.0.6 beta, if you install 1.0.5. stable this function will not work). This is very useful to handle file downloads, generated URIS can’t be hot-linked (after it expires), you can also use this mod to lock down directory for unregistered users.

Instructions for CentOS

Find and uncomment following line in httpd.conf:

mod_bw

The httpd web server doesn’t really have a way to control how much resources a given virtual host can have/ a user can request, this mod helps with this. You don’t want 1 user to use up all available bandwidth on your server… Fortunately this one is easy, direct from repo.

Instructions for CentOS

VirtualHost

It is time now to configure virtual host and give our special “video” directory power of mod_h264, mod_auth_token and mod_bw.

Create virtualhost containing following directives. What happens here is pretty simple. We create alias so that domain.com/video points to video directory in the filesystem. Same for /preview. But there is a difference on how we handle /video and /preview. /video is protected using mod_auth_token – files cannot be directly accessed and correct token (based on IP and time) is required. /preview is not protected and you can directly view all files there, but any .mp4 file accessed in this directory is rewritten to show only 10 sec clips (?start=400&end=500).

PHP FrontEnd

Lets me explain this briefly. It should be self explanatory to any programmer though.

  1. We have two functions. First function (generate_token) given filename generates token for mod_auth_token, without this we will not be able to access full length videos inside /var/video directory. Second one is just a simple example for managing sessions, not important for the scope of this article.
  2. I used video.js in this example, good but pricey alternative is jwplayer (pricey if you want to remove watermark, otherwise they also have free version).
  3. We have user sandro, he can be either level 0 or 1. 0 level can view only short clip, and 1 level can see full video.

Encoding

You will need to encode all your files into .mp4 container with h264 codec, but pay attention, I noticed handbreak encoded files don’t play on IOS. So use ffmpeg or avconv, whichever you like.

I prefer ffmpeg, as I have a simple way to increase volume using -vol flag, I couldn’t find same for avconv. You can also use non-experimental aac code libfaac.

If you have huge library of videos you can go through all your *.avi files and encode them into *.mp4, using this command (nohup makes sure you can close terminal window and continue encoding uninterrupted):

Leave a Reply

Your email address will not be published. Required fields are marked *