Page 1 of 1
MP3 Binary Interogation
Posted: Fri Jul 07, 2006 3:28 am
by JayBird
I am looking to veryfy that an MP3 file upload to a server is *actually* an MP3 file
I want to do this by interogating the binary of the file.
I think i have found the file spec for
MP3 files here - a little down the page.
I really have no idea where to start with this...could do with a few pointers on what i need to be checking for as i dont fully understand the file spec information, and how i will check this spec using PHP.
Any pointer appreciated.
Thanks
Posted: Fri Jul 07, 2006 3:34 am
by Benjamin
I saw a code snippet on the zend web site earlier that would pull the tags from mp3 files, perhaps it could be modified. I'll try to find it again...
Posted: Fri Jul 07, 2006 3:39 am
by feyd
getID3 can pull the ID3 information, but having ID3 tags does not make a MP3, unfortunately. You'd need to actually process each packet to ensure conformance to the specification(s) to thoroughly verify it's status. But then again, Pimptastic may not need such stringent verification.
Posted: Fri Jul 07, 2006 3:41 am
by Benjamin
http://www.zend.com/codex.php?id=160&single=1
Also I know there is some code here in the forum someplace for detecting a files type be it's contents...
Posted: Fri Jul 07, 2006 3:47 am
by JayBird
Well, the file spec says that the header of the MP3 file should look like this
Code: Select all
AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMM
Code: Select all
Sign(bits) Length (bits) Position Description
A 11 (31-21) Frame sync (all bits set)
B 2 (20,19) MPEG Audio version ID
00 - MPEG Version 2.5
01 - reserved
10 - MPEG Version 2 (ISO/IEC 13818-3)
11 - MPEG Version 1 (ISO/IEC 11172-3)
C 2 (18,17) Layer description
00 - reserved
01 - Layer III
10 - Layer II
11 - Layer I
D 1 (16) Protection bit
0 - Protected by CRC (16bit crc follows header)
1 - Not protected
etc. See link in fist post for more information
How would i check that the header bits match that? and would that be a good enough check to prove that it was an MP3 file
Posted: Fri Jul 07, 2006 4:02 am
by feyd
pack() and
unpack() (mostly the latter) can be used to pull out the information (
sscanf() can be used too) along with some fun with math and bitmasking..
If you are looking for basic verification only, looking at the MP3 headers may do just fine.
Posted: Fri Jul 07, 2006 4:25 am
by JayBird
feyd wrote:pack() and
unpack() (mostly the latter) can be used to pull out the information.
Holy smurf, after reading the manual, i have no idea how to use those functions
