Skip to content

Commit b7863e1

Browse files
authored
Merge pull request #314 from jbraendle/Issue#285
Issue#285
2 parents aebd639 + be52551 commit b7863e1

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

MetadataExtractor/Formats/Mpeg/Mp3Reader.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@ public sealed class Mp3Reader
88
{
99
// http://id3.org/mp3Frame
1010
// https://www.loc.gov/preservation/digital/formats/fdd/fdd000105.shtml
11+
// https://id3.org/id3v2.4.0-structure
1112

1213
public Directory Extract(SequentialReader reader)
1314
{
1415
var directory = new Mp3Directory();
1516

1617
var header = reader.GetInt32();
1718

19+
// If the file starts with ID3v2 data, try to skip over it for now.
20+
// Eventually we should extract this data properly.
21+
if ((header & 0xFFFFFF00) == 0x49443300) // "ID3"
22+
{
23+
// Adjust start to end of header
24+
var id3Bytes = reader.GetBytes(6);
25+
reader.Skip(id3Bytes[2] * 0x200000 + id3Bytes[3] * 0x4000 + id3Bytes[4] * 0x80 + id3Bytes[5]);
26+
header = reader.GetInt32();
27+
}
28+
1829
// ID: MPEG-2.5, MPEG-2, or MPEG-1
1930
int id = 0;
2031
switch ((header & 0x000180000) >> 19)
@@ -49,8 +60,7 @@ public Directory Extract(SequentialReader reader)
4960
break;
5061
}
5162

52-
53-
int protectionBit = (header & 0x00010000) >> 16;
63+
// int protectionBit = (header & 0x00010000) >> 16;
5464

5565
// Bitrate: depends on ID and Layer
5666
int bitrate = (header & 0x0000F000) >> 12;
@@ -75,8 +85,7 @@ public Directory Extract(SequentialReader reader)
7585
frequency = frequencyMapping[1, frequency];
7686
}
7787

78-
79-
int paddingBit = (header & 0x00000200) >> 9;
88+
// int paddingBit = (header & 0x00000200) >> 9;
8089

8190
// Encoding type: Stereo, Joint Stereo, Dual Channel, or Mono
8291
int mode = (header & 0x000000C0) >> 6;

MetadataExtractor/Formats/Mpeg/MpegAudioTypeChecker.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@ 2 Layer description
2323
11 - Layer I
2424
2525
Additional bits contain more information, but are not required for file type identification.
26+
27+
MP3 with ID3V2-Tags https://id3.org/id3v2.4.0-structure
28+
MP3-File with ID3V2-Tagging at start
2629
*/
2730

2831
public int ByteCount => 3;
2932

3033
public Util.FileType CheckType(byte[] bytes)
3134
{
35+
36+
// MP3-File with "ID3" at start
37+
if (bytes[0] == 0x49 && bytes[1] == 0x44 && bytes[2] == 0x33)
38+
return Util.FileType.Mp3;
39+
3240
// MPEG audio requires the first 11 bits to be set
3341
if (bytes[0] != 0xFF || (bytes[1] & 0xE0) != 0xE0)
3442
return Util.FileType.Unknown;

0 commit comments

Comments
 (0)