Hello annnarosse,
Thank you for using Apple Support Communities. It's my understanding that the rear camera on your iPhone has stopped working and you'd like to know what will happen to your Apple Music library if you restore to factory settings. You've come to the right place! I'm happy to help.
Restoring to factory setting may not be necessary to resolve this issue. If you haven't already, I recommend trying the steps in the following resource to help with your rear camera:
If the camera on your iPhone, iPad, or iPod touch isn't working
If you're prompted to restore, the music in your Apple Music library will be available after setting up your iPhone and signing in with the same Apple ID that you're currently using with Apple Music. I know content on any device can be very important. I recommend backing up your device before proceeding.
How to back up your iPhone, iPad, or iPod touch
Restore your iPhone, iPad, or iPod to factory settings
Have a nice day!