Using logs to get size of served video

I am playing around with a way to dynamically serve higher optimized (ie. smaller) video files if I get close to my bandwidth limit, so that I won't get hit with extra bandwidth charges. All this to make videoblogging more feasible.

Now, I can generate SMIL from PHP - SMIL is just an XML text file. The SMIL points to the movie file. I can save SMIL as a .mov file, which just gets picked up by Quicktime as a normal .mov file. So that lets me (PHP) decide which movie file to show (of, say, 3 versions I have stored, from small to large), IF PHP knows how much bandwidth the files have been using.

In come Apache server logs. With code like this in my httpd.conf file:

LogFormat "%U %B" video
CustomLog logs/videosize video

I can generate a logfile like this, which can then be parsed (by PHP or something else) for size of served movie files:

/video/davewinerwiener.mov 0
/video/davewinerwiener.mov 444802

The first line is when I access a movie file in the browser that's locally cached. The second line shows the size of the movie file served. Bingo.

Still, the logfile would grow very large very quickly. It would be nice to ONLY show .mov files, or only show files from a certain directory, instead of all the files accessed on our server. Scales better. I couldn't find a way of doing that though. There doesn't seem to be an appropriate setting in Apache's mod_log_config, although you can do conditionals with it, so there's some hope. Any ideas would be very welcome!

# Aug 7, 2004