Avoid dynamic allocations for output pictures
and improved handling of outputBuffers
This commit is a merge of Jan's work. Many thanks to him