Encode before copy metadata. fix #2832