Monthly Archives: February 2011

YUI Compressor Ant Task

I was working on a project recently that contained a number of JavaScript files. As part of the build process, I wanted to minimise/compress all of the JavaScript files. The first thing that came to mind was to use YUI Compressor.

I was using Ant at the time so I needed to create a target to compress the JavaScript files and then output them to wherever they needed to be outputted to. Problem: By default, YUI Compressor can only handle one file at a time; you can’t pass to it a list of files to process. Damn! Anyway, to cut a long story short, I created a custom Ant task to do that for me. Hoorah!

I’ve set-up a repository on Google Code where you can download the code that generates the custom Ant task. Yes, I know it’s fashionable to create repositories on GitHub but I mostly use Subversion and Mercurial so there!

Alternatively you can check out the project directly by issuing the following command:

hg clone https://yui-compressor-ant-task.googlecode.com/hg/ yui-compressor-ant-task

Technically, it is possible to get the desired behaviour using Ant’s apply task; see the post here and the example under the heading, “Minify your JavaScript and CSS files”. I must admit, I only came across this after I had already developed my version; however, there are still reasons to use it. YUI Compressor supports a number of different options and to include a sub-set of these using apply would start to get ugly and (possibly) cumbersome. My Ant task is a bit neater. Well, I think so anyway.

Body Recomposition Experiment

The other day my copy of The 4 Hour Body arrived. I read the author’s other book – The 4 Hour Work Week – a while ago so I thought this would be fun to read, especially as I recently joined a gym after about a 1.5 years of doing little in terms of exercise. Years ago I used to do a lot of weight lifting so I have always been interested in the science of exercise despite my recent hiatus. As I now have the time I thought I would try out some of the experiments in the book for myself.

First experiment: The Slow-Carb Diet or, as the book claims, “How to Lose 1.4 stone (9kg) in 30 Days Without Exercise!” I am going to start this tomorrow (Tuesday). Basically, none of the following are allowed: pasta, potatoes, bread, rice, cereal, milk, fruit etc, except for one day a week when you can eat whatever you like and have as much of it as you want. Sounds good to me!

Here’s an example of some of the meals I will be having:

  • Breakfast: Eggs, lentils, spinach
  • Lunch: Chicken, black beans, mixed veg, guacamole
  • Dinner: Fish, borlotti beans, more spinach, mixed veg

The only other thing I will be taking is a calcium and magnesium supplement (1 capsule a day); I intend on getting all the potassium I need from the copious amount of spinach I will be eating. I drink about 1.5 litres of water a day anyway so won’t need to change anything there. I intend to continue with my 3 gym sessions a week but I’ll probably keep it fairly light while I’m on this diet.

Judging by some of the body fat example pictures from the book (here and here) I reckon I am probably somewhere between 12-15% body fat. I still need to find a tape measure as I haven’t done any of the measurements, e.g. waist, bicep, thigh etc, as the book instructs you to do (twice!) before starting.

I am going to give it a go for at least two weeks but probably not much more than that. I don’t really need to lose weight but as I intend on going away somewhere warm for a few days soon it won’t hurt to try and get a bit more some definition for the beach 🙂

Update: I’ve added a food diary page to record everything I eat

It’s Quitting Time!

One week ago today (last Friday) I left the DMI project at the BBC. Was time for a change, among other things that I am not going to go into.

So what’s next? No idea. Downtime. Vacation. Catch up on sleep.

I’ve got a backlog of books to read and a few ideas for some projects that I have been meaning to start for a long time now, including a lot more writing.

In one word: Freedom

Creating Thumbnails From A Video With Flex

This technical note shows how to create a simple application in Flex to create thumbnails from a video as it plays. Unfortunately it’s not as simple as just writing the client code to generate a thumbnail from a video! Presumably because of DRM, changes must be made on the server to enable the client to access the raw video data.

What follows are the changes that must be made to both Flash Media Server (FMS) and Wowza Media Server and some sample client code. Restart the server once the changes have been made.

Flash Media Server

This section assumes that the application’s root directory is located at: /opt/adobe/fms/applications/vod/. If you are running FMS on Windows (why?) then the correct location will be wherever you installed it; the relative directory structure will be the same.

Either of the following solutions will work:

1) In the application’s root directory, modify Application.xml and add the following:

<Application>
  <Client>
    <Access>
       <AudioSampleAccess enabled="true">/</AudioSampleAccess>
       <VideoSampleAccess enabled="true">/</VideoSampleAccess>
    </Access>
  </Client>
</Application>

2) Create a file main.asc in the application’s root directory then add the following:

application.onConnect = function (client) {
	client.videoSampleAccess = “/”;
	client.audioSampleAccess = “/”;
	application.acceptConnection(client);
}

Wowza Media Server

This section assumes that the application’s root directory is: /Library/WowzaMediaServer/conf/vod/.
The changes are similar to the ones above for FMS. Again, either of the following will get the job done:

1) Open Application.xml and add the following:

<Client>
  <IdleFrequency>-1</IdleFrequency>
     <Access>
          <StreamReadAccess>*</StreamReadAccess>
	  <StreamWriteAccess>*</StreamWriteAccess>
          <StreamAudioSampleAccess>*</StreamAudioSampleAccess>
	  <StreamVideoSampleAccess>*</StreamVideoSampleAccess>
          <SharedObjectReadAccess>*</SharedObjectReadAccess>
	  <SharedObjectWriteAccess>*</SharedObjectWriteAccess>
     </Access>
</Client>

The important bit is highlighted in bold.

2) Create a custom Wowza module, which means some Java coding. There are instructions on the Wowza site for how to do this. The relevant bit of code looks like this:

public void onConnect(IClient client, RequestFunction function, AMFDataList params) {
    client.setStreamAudioSampleAccess(IClient.AUDIOSAMPLE_ACCESS_ALL);
    client.setStreamVideoSampleAccess(IClient.VIDEOSAMPLE_ACCESS_ALL);
}

Client

Once the changes have been made to the server all you have to do now is write the client bit. Fortunately, here’s one I made earlier:

Unfortunately I don’t have access to a publicly available streaming server so you’ll just have to take my word for it that the example works. I did test it locally first 🙂

The “interesting” bit is the function createThumbnail() in Main.mxml; the rest is just boiler-plate.

And that ladies and gentlemen is how to create thumbnails from a video in Flex. Interestingly enough you can do the same thing using the HTML5 video tag and the canvas API but I’ll leave that for another day.