Get MP4 Header Info
iPod 所用的音樂檔案格式為m4a,屬於mpeg4。要取得其header資訊,可至Freeware Advanced Audio Coder下載 faad2-2.5,匯入其下的faad2\common\mp4ff\mp4ff.dsp,編譯成 mp4ff.lib
How to use?
#pragma comment(lib, "mp4ffd.lib")
uint32_t read_callback(void *user_data, void *buffer, uint32_t length)
{
return fread(buffer, 1, length, (FILE*)user_data);
}
uint32_t seek_callback(void *user_data, uint64_t position)
{
return fseek((FILE*)user_data, position, SEEK_SET);
}
int main(int argc, char* argv[])
{
FILE *mp4File;
mp4ff_callback_t *mp4cb;
mp4ff_t *infile;
char *pcFile = "Z:\Leyline-so_wrong.m4a";
int j, k;
char *pVal;
char *tag = NULL, *item = NULL;
char szAnsi[256];
mp4File = fopen(pcFile, "rb");
mp4cb = malloc(sizeof(mp4ff_callback_t));
mp4cb->read = read_callback;
mp4cb->seek = seek_callback;
mp4cb->user_data = mp4File;
infile = mp4ff_open_read(mp4cb);
if (!infile) {
/* unable to open file */
fprintf(stderr, "Error opening file: %s\n", pcFile);
return 1;
}
pVal = NULL;
if (mp4ff_meta_get_title(infile, &pVal))
printf("title:%s\n", szAnsi);
if (mp4ff_meta_get_artist(infile, &pVal)) {
utf8_to_ansi(pVal, szAnsi);
printf("artist:%s\n", szAnsi);
}
if (mp4ff_meta_get_album(infile, &pVal))
printf("album:%s\n", pVal);
if (mp4ff_meta_get_genre(infile, &pVal))
printf("genre:%s\n", pVal);
//列舉
/* j = mp4ff_meta_get_num_items(infile);
for (k = 0; k <j; k++) {
if (mp4ff_meta_get_by_index(infile, k, &item, &tag)) {
if (item != NULL && tag != NULL) {
fprintf(stderr, "%s: %s\n", item, tag);
free(item); item = NULL;
free(tag); tag = NULL;
}
}
}
*/
return 0;
}