Rapper YG was shot early Friday morning at an L.A. recording studio … TMZ has learned.

Law enforcement sources tell us, it happened at around 1:45 AM in Studio City. We’re told someone shot YG 3 times in the hip.

Somehow the rapper was able to get in his car and someone from his group drove him to a nearby hospital.

Cops were called and found multiple shell casings and blood on the sidewalk. Police went to the hospital to interview YG but we are told he was “very uncooperative.”

YG’s rep says the injuries are not life threatening, and he’s doing fine.

We’re told the shooter is still on the loose.

The guy who shot YG may have unwittingly done it in front of an audience … unfortunately for him, an audience of cops.

We’ve learned multiple cameras may have captured the violence early Friday morning outside a San Fernando Valley recording studio/apartment complex, when YG was shot 3 times in the hip. The shooter is still on the loose.

Our sources say the cameras appear to have been in position to capture the shooting. LAPD detectives have already requested the video, which they’ll get within a day or 2.

What’s more … we’re told there are video cameras in the studio where YG was recording just before the shooting. Our sources say a number of people were in the studio and some sort of fight erupted shortly before shots were fired.

As for YG … he’s on the mend.