dhowden / tag

ID3, MP4 and OGG/FLAC metadata parsing in Go
BSD 2-Clause "Simplified" License
568 stars 77 forks source link

Reading ID3v2.4 tags failing #21

Closed cassava closed 8 years ago

cassava commented 8 years ago

When reading an MP3 with an ID3v2.4 tag, it doesn't read any of the tags.

Edit: this is what I thought, but it's not the case...

I've tracked it down to this: in the song file I have an embedded picture, which has a size that is significantly larger than the size of the header. Hence it reads one picture (which oddly returns with name == "", would actually expect APIC, right?), then offset > h.Size and the loop exits.

This all happens in the readID3v2Frames function.

cassava commented 8 years ago

In particular,

and it exits because invalid ID3 frame actually. This tag was written with easytag and it reads fine with other tag readers, e.g. mid3v2.

cassava commented 8 years ago

Hexdump | head:

00000000  49 44 33 04 00 40 00 03  22 6f 00 00 00 0c 01 20  |ID3..@.."o..... |
00000010  05 03 77 7b 5e 53 54 49  54 32 00 00 00 0e 00 00  |..w{^STIT2......|
00000020  03 57 68 65 6e 20 49 27  6d 20 47 6f 6e 65 54 50  |.When I'm GoneTP|
00000030  45 31 00 00 00 0d 00 00  03 33 20 44 6f 6f 72 73  |E1.......3 Doors|
00000040  20 44 6f 77 6e 54 50 45  32 00 00 00 0d 00 00 03  | DownTPE2.......|
00000050  33 20 44 6f 6f 72 73 20  44 6f 77 6e 54 41 4c 42  |3 Doors DownTALB|
00000060  00 00 00 12 00 00 03 41  77 61 79 20 46 72 6f 6d  |.......Away From|
00000070  20 54 68 65 20 53 75 6e  54 50 4f 53 00 00 00 06  | The SunTPOS....|
00000080  00 00 03 30 31 2f 30 31  54 52 43 4b 00 00 00 06  |...01/01TRCK....|
00000090  00 00 03 30 31 2f 31 32  54 43 4f 4e 00 00 00 05  |...01/12TCON....|
cassava commented 8 years ago

If I convert the file with ffmpeg, I get something else. Hexdump | head:

00000000  49 44 33 04 00 00 00 07  4f 78 54 49 54 32 00 00  |ID3.....OxTIT2..|
00000010  00 0f 00 00 03 57 68 65  6e 20 49 27 6d 20 47 6f  |.....When I'm Go|
00000020  6e 65 00 54 50 45 31 00  00 00 0e 00 00 03 33 20  |ne.TPE1.......3 |
00000030  44 6f 6f 72 73 20 44 6f  77 6e 00 54 50 45 32 00  |Doors Down.TPE2.|
00000040  00 00 0e 00 00 03 33 20  44 6f 6f 72 73 20 44 6f  |......3 Doors Do|
00000050  77 6e 00 54 41 4c 42 00  00 00 13 00 00 03 41 77  |wn.TALB.......Aw|
00000060  61 79 20 46 72 6f 6d 20  54 68 65 20 53 75 6e 00  |ay From The Sun.|
00000070  54 45 4e 43 00 00 00 0d  00 00 03 47 6f 6f 67 6c  |TENC.......Googl|
00000080  65 20 50 6c 61 79 00 54  52 43 4b 00 00 00 07 00  |e Play.TRCK.....|
00000090  00 03 30 31 2f 31 32 00  54 43 4f 4e 00 00 00 06  |..01/12.TCON....|
wader commented 8 years ago

Can you attach the header as a file?

cassava commented 8 years ago

How would I do that? exiftool will show a whole lot more information, and it claims that the id3 header size is invalid. For ID3v2.4 easytag uses libid3tag. Here is the output of exiftool -v3:

  ExifToolVersion = 10.10
  FileName = 11-Not On My Own.mp3
  Directory = .
  FileSize = 4782080
  FileModifyDate = 1460754252
  FileAccessDate = 1460983741
  FileInodeChangeDate = 1460754252
  FilePermissions = 33204
  FileType = MP3
  FileTypeExtension = MP3
  MIMEType = audio/mpeg
  MPEGAudioVersion = 3
  AudioLayer = 1
  AudioBitrate = 9
  SampleRate = 0
  ChannelMode = 0
  MSStereo = 0
  MPEG_Audio_Bit26-27 = 0
  IntensityStereo = 0
  CopyrightFlag = 0
  OriginalMedia = 1
  Emphasis = 0
  VBRFrames = 9192
  VBRBytes = 4772608
  VBRScale = 98
  Encoder = LAME3.96r
  LameVBRQuality = 0
  LameQuality = 2
  + [BinaryData directory, 8036 bytes]
  | LameMethod = 2
  | - Tag 0x0009, mask 0x0f (1 bytes, int8u[1]):
  |     00a5: 02                                              [.]
  | LameLowPassFilter = 180
  | - Tag 0x000a (1 bytes, int8u[1]):
  |     00a6: b4                                              [.]
  | LameBitrate = 160
  | - Tag 0x0014 (1 bytes, int8u[1]):
  |     00b0: a0                                              [.]
  | LameStereoMode = 4
  | - Tag 0x0018, mask 0x1c (1 bytes, int8u[1]):
  |     00b4: 46                                              [F]
  ID3Size = 9568
ID3v2.4.0:
  + [ID3v2_4 directory, 9558 bytes]
  | Warning = Encrypted frames currently not supported
  | Warning = Invalid ID3 frame size
cassava commented 8 years ago

This is a simple recording some friends of mine made with some tags encoded with the library. recording.zip

wader commented 8 years ago

You copy the first 200kb to a new file etc, something like dd if=file.mp3 of=file.header bs=1 count=200000 or use a hex editor

wader commented 8 years ago

But your solution works too 👍 ill have a look later

wader commented 8 years ago

So file is correct and i guess exiftool does not have extended header support 😄