Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last frame + ID3v1 Tag #57

Closed
MangaD opened this issue Jul 9, 2019 · 5 comments
Closed

Last frame + ID3v1 Tag #57

MangaD opened this issue Jul 9, 2019 · 5 comments

Comments

@MangaD
Copy link

MangaD commented Jul 9, 2019

Hello, I am a newbie to this library and am facing a problem that I'm not sure if it is my fault or the library's fault. I am trying to get the position of the ID3v1 tag in the file, if it exists. I am using the following code - based on the example provided in this repository - to get info regarding an MP3 file:

https://pastebin.com/3gghY7L3
https://pastebin.com/2iQb5FTz

The problem I'm facing is that the ID3v1 position is not set where the TAG starts, but where the last frame starts, which seems to be caused by the function mp3dec_decode_frame returning 0 samples for the last frame when there is an ID3v1 tag in the MP3 file. Any help?

@MangaD
Copy link
Author

MangaD commented Jul 12, 2019

Also don't forget the possibility of an enhanced tag being present:
https://en.wikipedia.org/wiki/ID3

@lieff
Copy link
Owner

lieff commented Jul 13, 2019

Hello) Sorry for the delay.

There no need to check ID3v1 in decoding loop, you can do it at the same place ID3v2 is handled. Here sample of skipping ID3v1 6fc51c3 . If condition is true, tag position to parse will be buf + buf_size - 128. Note that unlike ID3v2, ID3v1 detection is not 100% safe, there possibility that "TAG" marker accidentally found in middle of real mp3 frame, so I put it under define.

@MangaD
Copy link
Author

MangaD commented Jul 13, 2019

Hello. Thank you for the reply and commit! The odds of "TAG" being in a frame exactly at buf_size - 128 should be low so I'll take the risk. I changed the code a bit to support enhanced tags:

	size_t id3v1size = 0;
#ifdef MINIMP3_SKIP_ID3V1
	if (buf_size > 128 && !strncmp((char *)buf + buf_size - 128, "TAG", 3)) {
		buf_size -= 128;
	        id3v1size += 128;
	        if (buf_size > 227 && !strncmp((char *)buf + buf_size - 227, "TAG+", 4)) {
	        	buf_size -= 227;
	        	id3v1size += 227;
	        }
	}
#endif
	info->id3v1size = id3v1size;

What worries me about this solution is that I need to get all the frames in the MP3 file, but summing up all frame_bytes in the loops is not counting the last frame(s) when an IDv1 tag is present. @.@
But logically that would seem to be the best solution.

@lieff
Copy link
Owner

lieff commented Jul 13, 2019

Oh, yes, I forgot about extended ID3v1 tag. I've add it here 43caa38 .
I did not find any software which writes it however, to make a proper test file like vectors/l3-id3v1.bit .

@MangaD
Copy link
Author

MangaD commented Jul 13, 2019

According to Wikipedia, the extended block is not an official standard and is only supported by few programs, not including XMMS or Winamp. So it is no big deal. I will close this issue now, thank you very much for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants