mkv: Refactor mkv_write_packet