The following code was found at http://www.alecjacobson.com/weblog/?p=1875
The page suffered from bad formatting so the contents have been pasted here for easier readibility.
// Modified from "Video Texture" code
// Copyright (C) 2009 Arsalan Malik (arsalank2@hotmail.com)
//