Factor out bitstream parsing and copying.