sergree / matchering

🎚️ Open Source Audio Matching and Mastering
https://pypi.org/project/matchering/
GNU General Public License v3.0
1.29k stars 151 forks source link

How to work with mp3s? #39

Closed nothingcomeseasy closed 2 years ago

nothingcomeseasy commented 2 years ago

Hello guys! matchering is an amazing lib, thank you very much!

I wanna try to play around with some mp3 files in matchering but can't find any documentation about it

I want to upload a target and reference (both mp3) and extract the mastered target as mp3 as well. Is it possible? where can I find information about the python syntax to make it possible?

Thank you!

sergree commented 2 years ago

Hello 🙂 Thank you for your kind words! They inspire. 😅

I'm sorry, but matchering can only read mp3 files. It does this via ffmpeg: https://github.com/sergree/matchering/blob/master/matchering/loader.py#L39 https://github.com/sergree/matchering/blob/master/matchering/loader.py#L49-L73

He tries to do this if he failed to open the file using pysoundfile library.

I did not add the ability to save mp3 using ffmpeg, because mp3 is a proprietary format and it had some legal restrictions on the creation of mp3 files. At the moment, only formats supported by pysoundfile are available for writing: https://pysoundfile.readthedocs.io/en/latest/_modules/soundfile.html Basically it is WAV, FLAC, OGG.

If you need to save to mp3, then you need to make your own wrapper for matchering. 🙏

nothingcomeseasy commented 2 years ago

@sergree thanks for your answer! All works perfectly with .wav but even reading the loader.py I still don't understand how to load the mp3 files (i'm new to programming languages). I had installed ffmpeg and can work with it with other audio libraries, so it's not the problem I think.

Shouldn't the code below work? I'm getting this error: "ModuleError: 4001: Audio stream error in the TARGET file"

mg.process(

The track you want to master

target="my_song.mp3",
# Some "wet" reference track
reference="some_popular_song.mp3",
# Where and how to save your results
results=[
    mg.pcm16("my_song_master_16bit.wav"),
    mg.pcm24("my_song_master_24bit.wav"),
],

)

sergree commented 2 years ago

@nothingcomeseasy, yes, i think such code should work if you have installed ffmpeg.

ffmpeg should be available in the PATH variable. If you are on windows, try to use Win + R, then cmd. And try to use ffmpeg at the console window screen. If it gives some error like "not found" then matchering can't find your ffmpeg.

Try to google something like add ffmpeg to path This is the guide for Windows 10: https://www.thewindowsclub.com/how-to-install-ffmpeg-on-windows-10

I hope that helps