mackron / dr_libs

Audio decoding libraries for C/C++, each in a single source file.
Other
1.27k stars 206 forks source link

Get Metadata from MP3 or WAV files #149

Open julianxhokaxhiu opened 4 years ago

julianxhokaxhiu commented 4 years ago

Hi,

I've been tinkering with your libraries, and so far I was able to get the metadata ( Vorbis comments ) out of FLAC files using the onMeta callbacks pared with drflac_init_vorbis_comment_iterator/drflac_next_vorbis_comment functions.

I was looking for something similar on the dr_mp3.h and dr_wav.h decode libraries, but I was not able to find a pattern nor anything that goes near to the terms "tag", "comment" or "metadata".

Would you be able to let me know if the libraries to support at all this functionality?

Thank you in advance, Julian

mackron commented 4 years ago

With dr_wav, you can use drwav_init_*_ex() and implement a callback for the onChunk parameter. That will then let you handle any chunk. See here for more info: https://github.com/mackron/dr_libs/blob/fc559fe440d9a1b1bdc6661ccd5b96e70cf00d7e/dr_wav.h#L407

For dr_mp3 there is no API for extracting metadata, unfortunately.

julianxhokaxhiu commented 4 years ago

Thank you for the reply :)

I'll to tinker with the dr_wav and let you know how it goes. Meanwhile, do you have a plan on extracting the metadata out of MP3 files too? Audacity for eg. allows you to put some Metadata in the file so I suppose there is some sort of specification out there right? Would it be too complicated for you to be implemented?

Thanks again in advance, Julian

julianxhokaxhiu commented 4 years ago

Allright, so I've made some progress. I am now able to get the chunk content in a buffer, but I have to do some manual parsing to extract what I need. Is there a reference document or something I can use to build this correctly? I'm currently reading chunks on 4KB per callback, not sure if it's the best way.

Thank you in advance for any help, is really appreciated!

//EDIT: Found something http://www.robotplanet.dk/audio/wav_meta_data/

mackron commented 4 years ago

Yes, manual passing will be required. Reading in 4KB chunks shouldn't be necessary unless you have some unusual performance requirements. Need to be careful not to read beyond the chunk, the size of which can be extracted from the chunk header passed into the onChunk callback.

This is another reference I've used in the past: https://sites.google.com/site/musicgapi/technical-documents/wav-file-format

For MP3, dr_mp3 actually wraps around minimp3. It would require some manual processing outside of minimp3 to handle the various ID3 tags. The author of minimp3 is maintaining a sort of extended high level version of it called minimp3_ex which detects these tags, but I'm not sure if they're reported back to the application for handling. From what I saw it's just for skipping over them elegantly. I may add support for it at some point, but I not right now.

julianxhokaxhiu commented 4 years ago

Yes, manual passing will be required. Reading in 4KB chunks shouldn't be necessary unless you have some unusual performance requirements. Need to be careful not to read beyond the chunk, the size of which can be extracted from the chunk header passed into the onChunk callback.

Indeed I figured this out this afternoon but I forgot to actually mention it here, but still thanks for the heads up. I also figured out the way to parse chunks so I'll add my implementation now, should be easy to detect all tags :)

This is another reference I've used in the past: https://sites.google.com/site/musicgapi/technical-documents/wav-file-format

Thanks, again for the heads up!

For MP3, dr_mp3 actually wraps around minimp3. It would require some manual processing outside of minimp3 to handle the various ID3 tags. The author of minimp3 is maintaining a sort of extended high level version of it called minimp3_ex which detects these tags, but I'm not sure if they're reported back to the application for handling. From what I saw it's just for skipping over them elegantly. I may add support for it at some point, but I not right now.

Indeed I notice that most of the code is literally skipping tags and there's no point in the lib actually passing them. Too bad :( Not urgent though. At the moment I'm happy I am able to get them from FLAC, WAV and Ogg files ( using another library ). MP3 can wait and they're not really urgent :) Still thanks, feel free to ping me on this issue ASAP you get something implemented. Cheers!

raysan5 commented 4 years ago

Personally, I think it would be interesting to have the possibility to retrieve the ID3 chunk of data from the MP3 file, to allow processing it on user side. Just for reference, here some ID3 tag info: https://en.wikipedia.org/wiki/ID3

EDIT: Investigated a bit about ID3v2.3 (it seems the standard tag) and it's not trivial to process all the possible contained data, ID3v1 placed at the end of the file is way simpler. In any case, it would be nice to get the chunk...