This odd-looking behavior has yet to be fully explained or proven and there are many proposed explanations.
Ants containing formic acid are preferred, but occasionally millipedes will be used. These insects secrete liquids containing defense chemicals such as formic acid. The acids could act as an insecticide or fungicide and inhibit mites and feather parasites. Anting is more frequently done during molting season. Could this have a soothing effect on the skin during the discomfort of molting and rapid growth of new feathers ?
Birds have also been observed anting with marigolds (which contain the natural insecticide pyrethrum) and even with mothballs (which contain the insecticide naphthalene).
No matter what the reason, it is a fascinating avian behavior not often observed in the wild. Should you be fortunate to witness a bird engaging in anting, stop, look, and marvel at one of the intricacies of nature.
Resources and further reading: Birdwatchingdaily.com/blog ; Wikipedia.com ; npr.org ; birds.com/blog