This patch moves the stream header generation into a separate API call to facilitate stream stitching and external GOP parallelism. The output bitstream has an extra NULL byte in it as a result of this change, but it decodes just fine.