Will this work with a cash out refinance?

No, because one of the necessary components to guarantee you’ll save money and shave years off your mortgage is that your new loan amount must be the same as your current mortgage’s outstanding balance. On a cash-out refinance of course that is not the case.