Results 1 to 4 of 4

Thread: Detecting valid mp3 or not

  1. #1

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512

    Detecting valid mp3 or not

    Does anyone know if there is a way to detect if an mp3 file is a genuine mp3 file instead of a .txt file or something renamed to .mp3? Thanks for any feedback
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  2. #2
    Lively Member RobIII's Avatar
    Join Date
    Jul 2002
    Location
    Netherlands
    Posts
    112
    I doubt if there is a safe way. An MP3 file is just raw data wich doesn't really have a header or something. So it's going to get hard, i can tell you that much...

    I found some info, but again, no real verification. As you can see, the header is just a bunch of bits. They can be any value. If it were "MP3" and then the rest of the bits it would've been easier.

    VB Code:
    1. Mpeg 1.0/2.0 LayersI, II and III header and trailer formats
    2. -----------------------------------------------------------
    3. * HEADER
    4.  
    5.  
    6. bits name              comments
    7. --------------------------------------------------
    8. 11   sync              0xFFF
    9. 2    version           1=mpeg1.0, 0=mpeg2.0
    10. 2    lay               4-lay = layerI, II or III
    11. 1    error protection  0=yes, 1=no
    12. 4    bitrate_index     see table below
    13. 2    sampling_freq     see table below
    14. 1    padding
    15. 1    extension         see table below
    16. 2    mode              see table below
    17. 2    mode_ext          used with "joint stereo" mode
    18. 1    copyright         0=no 1=yes
    19. 1    original          0=no 1=yes
    20. 2    emphasis          see table below
    21. --------------------------------------------------
    22.  
    23. - bitrate_index
    24.  
    25. . mpeg1.0
    26.  
    27.             1  2  3   4   5   6   7   8   9  10  11  12  13  14
    28. layer1     32 64 96 128 160 192 224 256 288 320 352 384 416 448
    29. layer2     32 48 56  64  80  96 112 128 160 192 224 256 320 384
    30. layer3     32 40 48  56  64  80  96 112 128 160 192 224 256 320
    31.  
    32. . mpeg2.0
    33.  
    34.             1  2  3   4   5   6   7   8   9  10  11  12  13  14
    35. layer1     32 48 56  64  80  96 112 128 144 160 176 192 224 256
    36. layer2      8 16 24  32  40  48  56  64  80  96 112 128 144 160
    37. layer3      8 16 24  32  40  48  56  64  80  96 112 128 144 160
    38.  
    39.  
    40. - sampling_freq
    41.  
    42. . mpeg1.0
    43.  
    44.     0     1     2    
    45.  
    46. 44100 48000 32000
    47.  
    48. . mpeg2.0
    49.  
    50.     0     1     2    
    51.  
    52. 22050 24000 16000
    53.  
    54.  
    55. - mode:
    56.  
    57. 0 "stereo"
    58. 1 "joint stereo"
    59. 2 "dual channel"
    60. 3 "single channel"
    61.  
    62.  
    63. - mode extension:
    64.  
    65. 0      MPG_MD_LR_LR
    66. 1      MPG_MD_LR_I
    67. 2      MPG_MD_MS_LR
    68. 3      MPG_MD_MS_I
    69.  
    70. jsbound :
    71.  
    72.    mode_ext     0  1   2   3
    73. layer
    74. 1               4  8  12  16
    75. 2               4  8  12  16
    76. 3               0  4   8  16
    77.  
    78.  
    79. - emphasis:
    80.  
    81. 0 "none"
    82. 1 "50/15 microsecs"
    83. 2 "reserved"            must not be used !
    84. 3 "CCITT J 17"
    85.  
    86.  
    87.  
    88.  
    89. * TRAILER
    90.  
    91. at end of file - 128 bytes
    92.  
    93. offset  type  len   name
    94. --------------------------------------------
    95. 0       char  3                   "TAG"
    96. 3       char  30    title
    97. 33      char  30    artist
    98. 63      char  30    album
    99. 93      char  4     year
    100. 97      char  30    comments
    101. 127     byte  1     genre
    102. --------------------------------------------
    103.  
    104. - genre :
    105.  
    106.  0    "Blues"
    107.  1    "Classic Rock"
    108.  2    "Country"
    109.  3    "Dance"
    110.  4    "Disco"
    111.  5    "Funk"
    112.  6    "Grunge"
    113.  7    "Hip-Hop"
    114.  8    "Jazz"
    115.  9    "Metal"
    116. 10    "New Age"
    117. 11    "Oldies"
    118. 12    "Other"
    119. 13    "Pop"
    120. 14    "R&B"
    121. 15    "Rap"
    122. 16    "Reggae"
    123. 17    "Rock"
    124. 18    "Techno"
    125. 19    "Industrial"
    126. 20    "Alternative"
    127. 21    "Ska"
    128. 22    "Death Metal"
    129. 23    "Pranks"
    130. 24    "Soundtrack"
    131. 25    "Euro-Techno"
    132. 26    "Ambient"
    133. 27    "Trip-Hop"
    134. 28    "Vocal"
    135. 29    "Jazz+Funk"
    136. 30    "Fusion"
    137. 31    "Trance"
    138. 32    "Classical"
    139. 33    "Instrumental"
    140. 34    "Acid"
    141. 35    "House"
    142. 36    "Game"
    143. 37    "Sound Clip"
    144. 38    "Gospel"
    145. 39    "Noise"
    146. 40    "AlternRock"
    147. 41    "Bass"
    148. 42    "Soul"
    149. 43    "Punk"
    150. 44    "Space"
    151. 45    "Meditative"
    152. 46    "Instrumental Pop"
    153. 47    "Instrumental Rock"
    154. 48    "Ethnic"
    155. 49    "Gothic"
    156. 50    "Darkwave"
    157. 51    "Techno-Industrial"
    158. 52    "Electronic"
    159. 53    "Pop-Folk"
    160. 54    "Eurodance"
    161. 55    "Dream"
    162. 56    "Southern Rock"
    163. 57    "Comedy"
    164. 58    "Cult"
    165. 59    "Gangsta"
    166. 60    "Top 40"
    167. 61    "Christian Rap"
    168. 62    "Pop/Funk"
    169. 63    "Jungle"
    170. 64    "Native American"
    171. 65    "Cabaret"
    172. 66    "New Wave"
    173. 67    "Psychadelic"
    174. 68    "Rave"
    175. 69    "Showtunes"
    176. 70    "Trailer"
    177. 71    "Lo-Fi"
    178. 72    "Tribal"
    179. 73    "Acid Punk"
    180. 74    "Acid Jazz"
    181. 75    "Polka"
    182. 76    "Retro"
    183. 77    "Musical"
    184. 78    "Rock & Roll"
    185. 79    "Hard Rock"
    186. 80    "Unknown"
    187.  
    188.  
    189.  
    190. - frame length :
    191.  
    192. . mpeg1.0
    193.  
    194. layer1 :
    195.  (48000*bitrate)/sampling_freq + padding
    196. layer2&3:
    197.  (144000*bitrate)/sampling_freq + padding
    198.  
    199. . mpeg2.0
    200.  
    201. layer1 :
    202.  (24000*bitrate)/sampling_freq + padding
    203. layer2&3 :
    204.  (72000*bitrate)/sampling_freq + padding
    Rob.

    Window XP: From the makers of DoubleSpace...

    Press ANY key... NO, NO, NO!!! NOT THAT ONE!!!!

  3. #3
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    I think you need to find information about the header of MP3 files.

  4. #4

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Cheers Guys. Thanks RobIII, thats what i figured. I didnt know if some clever sod had devised a way of detecting it. trouble is, if i rename a text file as .mp3 my app will allow it to play but because it isnt a real mp3 file, winamp just sits there in limbo and crashes the whole app! I guess all i can do now is do a test after 3 seconds or so and if its 'Playing' but the track position is still at zero i can stop the track and report an error. Thanks for your time tho!
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width