Search code examples
phpmysqlfilemp3format

how to store and search mp3 by its content


I want to store multiple mp3 files and search them by giving some part of song, to detect which song it is.

I am thinking of storing all binary content in mysql and when I want to search for a specific song by content I will take some middle portion of song and actually match it with the binary data in MySQL.

My questions are:

  1. Is this a reasonable way to find songs by their content?
  2. Is it right to store the songs' content in the database or should I use the filesystem?

Solution

  • This is not going to work. MP3 is a "lossy" format. That means that it constantly alters subtle nuances of the music when encoding, thus producing totally different byte-wise data on almost every encoding for the same song.

    Also, even in an uncompressed format like WAV, two identical records at different volumes will produce different byte data. So, it is impossible to compare music by comparing the byte values of the file's contents.

    A binary comparison will work only for two exact identical copies of the same MP3 file. It won't even work anymore when you re-encode the same MP3 file with identical settings.

    Comparing music is not a trivial matter, several approaches exist but to my knowledge none that can be used in PHP.

    If you're lucky, there exists a web service that allows some kind of matching. Expect it to be commercial in some way, though - I doubt we are at the stage where this kind of thing can be used free of charge.