Actually, looks like popcorn has some code to do this.

I'll try that and go from there.