Patch by Josh Allmann, joshua dot allmann at gmail, original code by Ronald S Bultje. Originally committed as revision 24236 to svn://svn.ffmpeg.org/ffmpeg/trunk