如何确定图像隐藏在 ID3v2 标签中的位置?
我正在尝试从 mp3 中加载 jpg(我在 Flash 中执行此操作,但这既不在这里也不在那里),并且我在十六进制编辑器中打开了一些 MP3,而标签的其余部分是很清楚,图像部分是个谜。有一个标签“image/jpeg”,但我期望类似于图像的字节长度或界定图像末尾的字符串键,但我没有看到任何此类内容,并且标签上的文档完全没有帮助。
希望对我在这里寻找的东西有一些指导。惊讶于结果是多么不直观!
TIA
I'm trying to load the jpg out of an mp3 (I'm doing this in Flash, but that's neither here nor there), and I've pulled open a few MP3s in a hex editor and while the rest of the tag is pretty clear, the image part is a mystery. There is a label "image/jpeg" but then I expect something resembling a byte length for the image or a string key that demarcates the end of the image, but I see nothing of the kind and the documentation on the tag is entirely unhelpful.
Would love some guidance on what I am looking for here. Surprised at how unintuitive this is turning out!
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然我通常会提倡 msw 的解决方案,但该网站似乎没有 Flash 的库。但是,它确实具有 ID3v2 规范。如果您查看第 4 节,
ID3v2 框架概述
,您将看到框架标头包括框架的大小,但不包括标头。我相信可以安全地假设可以从那里计算图像大小。PD:我假设您知道 ID3v2 标签的工作原理。如果您不这样做,我建议您至少粗略地浏览一下规范。基本上,有一个标头、一个扩展标头,然后是包含标签数据的一个或多个帧(每个数据一帧),最后是填充。
编辑:出于测试目的,我在十六进制编辑器中打开了一张带有已知标签数据的 MP3。找到一个名为
APIC
的帧,将指定的字节数复制到一个新文件中,并保存为test.jpg
。不太有效。进一步挖掘,我发现了框架规范。具体来说,第 4.14 节,
附加图片
,它描述了帧的各种“子标题”(1 字节文本编码、零分隔 mimetype、1 字节图片类型和零分隔描述) 。因此,我从数据中删除了该信息,并将剩余部分复制到 Windows 能够显示的新 jpg 中。因此,技术是:
While I'd normally advocate msw's solution, that site doesn't seem to have a lib for Flash. However, it DOES have the ID3v2 specification. If you look at section 4.,
ID3v2 frame overview
, you'll see the frame header includes the frame's size, not including the header. I believe it's safe to assume the image size can be calculated from there.PD: I'm assuming you know how ID3v2 tags work. In case you don't, I recommend you give at least a cursory glance at the spec. Basically, there's a header, an extended header, then one or more frames containing the tag's data (one frame per datum) and finally padding.
EDIT: For testing purposes I opened one of my MP3s with known tag data in my hex editor. Found a frame named
APIC
, copied the specified number of bytes into a new file and saved it astest.jpg
. Didn't quite work.Digging further, I found the frame spec. Specifically, Section 4.14,
attached picture
, which describes a "subheader" of sorts for the frame (1-byte text encoding, zero-delimited mimetype, 1-byte picture type and a zero-delimited description). So I trimmed that information out of the data and copied the remainder onto a new jpg, which Windows was able to show.Therefore, the technique is:
除非你喜欢痛苦,否则不要重新发明那个轮子。这是为您完成工作的库的一个来源。
Don't reinvent that wheel unless you like pain. This is but one source for libraries that do the work for you.