Redesigned the encoder and muxer back-end to fix a crash in libav/ffmpeg. Apparently you aren't allowed to delete the encoders before the trailer has been written. Also some minor other changes.