Do I need to get the rights to music used in my film if I'm not charging people to view it?
Internet Filmmakers' FAQ
The short answer is yes. Copyright law prevents distribution and public performance of protected works, regardless of whether money changes hands or not. It's the public performance aspect, not the money which causes problems with copyright.
If you do not hold the necessary rights for music (or any other copyright material) used in your film, then you cannot show it to anyone in a public environment. This includes standard types of exhibition (theatrical, television etc), and also includes public performance such as showing your film in festivals, schools, pubs, prisons, the town square, on airplanes, and of course on the Internet (e.g. YouTube, social media etc).
And you should note that there is virtually no 'fair use' defense for using copyrighted music in your film without permission. The concept of fair use does exist in copyright, but varies from country to country, and does not relate to things like how much of a particular song you use, or whether you charge for the resulting work or not. And remember, in most cases it is on you to prove your usage of copyright material constitutes fair use, not the other way around (meaning you will need to engage lawyers to defend any claim made against you by a copyright holder).
More information on music copyright can be found in the Legal Issues section of the Internet Filmmaker's FAQ.