为什么 libFLAC 的 FLAC__metadata_get_tags 函数不是确定性的?
在涉足 libFLAC 时,我尝试使用此 C 程序使用 FLAC__metadata_get_tags 函数:
#include <stdio.h>
#include <FLAC/metadata.h>
int main() {
FLAC__StreamMetadata* metas;
if (FLAC__metadata_get_tags("/tmp/test.flac", &metas) && metas != NULL) {
for (int i = 0;; i++) {
printf("type: %d, length: %d\n", (metas+i)->type, (metas+i)->length);
if ((metas+i)->is_last) {
break;
}
}
FLAC__metadata_object_delete(metas);
}
}
多次运行此程序时,我会得到不同的输出。类型 0 (FLAC__METADATA_TYPE_STREAMINFO
) 的元数据条目数量似乎有所不同。有时我什至得到未定义的类型和负长度。
这是为什么?我希望程序总是给出相同的输出。我也不确定长度为 0 甚至负长度的元数据条目应该意味着什么。
下面是一个执行示例:
$ clang -I/usr/local/include -L/usr/local/lib -lFLAC -logg test.c && ./a.out
type: 4, length: 213
type: 0, length: 0
type: 0, length: 0
type: 11, length: 1083592000
type: -538976289, length: 0
While dabbling with libFLAC I tried out the FLAC__metadata_get_tags
function with this C program:
#include <stdio.h>
#include <FLAC/metadata.h>
int main() {
FLAC__StreamMetadata* metas;
if (FLAC__metadata_get_tags("/tmp/test.flac", &metas) && metas != NULL) {
for (int i = 0;; i++) {
printf("type: %d, length: %d\n", (metas+i)->type, (metas+i)->length);
if ((metas+i)->is_last) {
break;
}
}
FLAC__metadata_object_delete(metas);
}
}
When running this program multiple times, I get different outputs. There seems to be a varying number of metadata entries with type 0 (FLAC__METADATA_TYPE_STREAMINFO
). Sometimes I even get undefined types and negative lenghts.
Why is that? I would expect the program to always give the same output. I'm also not sure what a metadata entry with length 0 or even a negative length is supposed to mean.
Here is one example execution:
$ clang -I/usr/local/include -L/usr/local/lib -lFLAC -logg test.c && ./a.out
type: 4, length: 213
type: 0, length: 0
type: 0, length: 0
type: 11, length: 1083592000
type: -538976289, length: 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
FLAC__StreamMetadata
不是元数据列表,它是一个元数据,并且只填充一个TYPE_VORBIS_COMMENT
。https://github.com/xiph/flac/blob/27c615706cedd252a206dd77e3910dfa395dcc49/src/libFLAC/metadata_iterators.c#L217
我找到了如何迭代它的代码,来自 https://isrc.iscas.ac.cn/gitlab/mirrors/github.com/musicplayerdaemon_mpd/-/blob/6419cc54ac200b217d99ee35d1e2d57dbfda3f55/src/decoder/flac_plugin.c:
在从 < 下载的 .flac 上一个href="https://helpguide.sony.net/high-res/sample1/v1/en/index.html" rel="nofollow noreferrer">https://helpguide.sony.net/high-res/sample1/ v1/en/index.html 输出:
总的来说,当有疑问时 - 当项目是开源的时,检查源代码。
FLAC__StreamMetadata
is not a list of metadata, it's one metadata, and only oneTYPE_VORBIS_COMMENT
is filled.https://github.com/xiph/flac/blob/27c615706cedd252a206dd77e3910dfa395dcc49/src/libFLAC/metadata_iterators.c#L217
I found code how to iterate over it, from https://isrc.iscas.ac.cn/gitlab/mirrors/github.com/musicplayerdaemon_mpd/-/blob/6419cc54ac200b217d99ee35d1e2d57dbfda3f55/src/decoder/flac_plugin.c :
On the .flac downloaded from https://helpguide.sony.net/high-res/sample1/v1/en/index.html outputs:
Overall, when in doubt - when the project is open-source, check sources.