This is not based on lucas work due to code divergence (its less work this way than trying to merge from a split based on 2 years outdated code) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Based on code from Carl Eugen Hoyos, Michael Niedermayer and Paul B Mahol.