If you get any image that is 5000px wide and 3000px tall, and you have 128 mb of ram. You will get a segfault.
Shouldn't the encoder "know" how much memory is left on the system and just use that given amount at most... Even though it slows down the processing? At least it doesnt seg fault.