如何确定图像隐藏在 ID3v2 标签中的位置?

发布于 2024-11-02 01:59:01 字数 224 浏览 5 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

開玄 2024-11-09 01:59:01

虽然我通常会提倡 msw 的解决方案,但该网站似乎没有 Flash 的库。但是,它确实具有 ID3v2 规范。如果您查看第 4 节,ID3v2 框架概述,您将看到框架标头包括框架的大小,但不包括标头。我相信可以安全地假设可以从那里计算图像大小。

PD:我假设您知道 ID3v2 标签的工作原理。如果您不这样做,我建议您至少粗略地浏览一下规范。基本上,有一个标头、一个扩展标头,然后是包含标签数据的一个或多个帧(每个数据一帧),最后是填充。

编辑:出于测试目的,我在十六进制编辑器中打开了一张带有已知标签数据的 MP3。找到一个名为APIC的帧,将指定的字节数复制到一个新文件中,并保存为test.jpg。不太有效。

进一步挖掘,我发现了框架规范。具体来说,第 4.14 节,附加图片,它描述了帧的各种“子标题”(1 字节文本编码、零分隔 mimetype、1 字节图片类型和零分隔描述) 。因此,我从数据中删除了该信息,并将剩余部分复制到 Windows 能够显示的新 jpg 中。

因此,技术是:

  • 从帧头获取帧大小。
  • 解析出帧子头的帧开头并将其删除。 (4 到无限字节之间的任意位置)
  • 根据剩余字节数计算图像大小。

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 as test.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:

  • Acquire frame size from frame header.
  • Parse out the beginning of the frame for the frame subheader and remove it. (Anywhere between 4 and infinite bytes)
  • Calculate image size based on remaining number of bytes.
萧瑟寒风 2024-11-09 01:59:01

除非你喜欢痛苦,否则不要重新发明那个轮子。这是为您完成工作的库的一个来源

Don't reinvent that wheel unless you like pain. This is but one source for libraries that do the work for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文