This patch is based on a patch by John Stebbins Signed-off-by: Michael Niedermayer <michaelni@gmx.at>