Initialize buffer index

Buffer index was not being initialized and the memory for the encoder is allocated (usually) with malloc. This leads to the potential for index to be non-zero, which could cause an invalid memcpy when writing to the buffer.