There are all kinds of ways to do this. Mesh Warp, Bezier warp, liquefy, displacement map.
You could even take your flag shapes into illustrator and use the blend tool then expand then release to layers and create your animation that way. Here is a zillion year old tutorial on that technique.
Tried bezier warp, turned out great! Thank you!