Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine that a particular file is in fact an MP3 file?

Tags:

c#

How can I determine that a particular file (which may or may not have an ".mp3" file extension) is in fact an MP3 file? I wish to do this in C#.

like image 798
user922907 Avatar asked Sep 04 '11 22:09

user922907


1 Answers

According to http://www.garykessler.net/library/file_sigs.html an mp3 file will always start with ID3 (hex 49 44 33) However, presence of these bytes only mean that the file is tagged with ID3 information. If this signature is not found, it could be an untagged mp3 file. To determine this, check out the mp3 file structure and you'll see that an mp3 frame starts with the signature ff fb (hex).

So :

  • if file starts with hex 49 44 33

or

  • if file starts with hex ff fb

it's safe to assume that it's an MP3.

like image 152
fvu Avatar answered Oct 07 '22 04:10

fvu