enc_qsv: factor out the encoding loop.