Simplify, use avctx->frame_number.