I didn't check a Mask option, but seems to me more natural to use an Object as a Mask and Shadow Catcher in once, so shadow follow the shape.
Alpha Over node seems to be working as expected.
Notes:
- Image in my 3Dviewport is an Empty object for a reference it doesn't influence a render. For the same effect (and probably easier for video) is toyou can use image as Bacgroudbacgroud for Cameracamera (Camera Properties > Background Images) that can be video as well.
- With Object ID pass or Cryptomatte you can separate shadow and adjust if needed.



