Turns out the Intel API for QSV is pretty buggy. There are lots of reports online of random failures and hangs.
I switched us to a different API offered by Windows. It uses the same QuickSync CPU features under the hood, but is better maintained by Microsoft and more stable.