Modded to encode to an existing stream.