I took a swing at implementing this myself already, but it was more difficult than i anticipated. The ability to do multi-pass encoding would help to improve the quality:filesize ratio, though.