Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I query chapter metadata from a m4a file?

I need to write some code that will let me query a m4a file and extract the chapter information out. Including:

  • chapter name
  • chapter start time
  • chapter artwork

I did some quick searching and it seems this is viewed as proprietary information by Apple? I found some discussions, but most were from 2005. Also there have been some similar questions on here, but more for CREATING m4a files with chapters, not querying.

Is this just something I have to DIY, cause there isn't a nice apple API for me to use? Or am I missing something obvious?

Also, ideally I need whatever technique I end up using to work on the iPhone.

like image 882
pj4533 Avatar asked Nov 05 '22 20:11

pj4533


2 Answers

The metadata tags system is Apple-proprietary. To work with the tags, you have to (sigh) reverse-engineer it or work with a library that has already done this.

I found the following links, but honestly it seems like you will have to pull out the hex editor.

Binary format info (basic spec for generic tags)

Perl library for working with M4A files.

like image 166
BobMcGee Avatar answered Nov 15 '22 11:11

BobMcGee


Turns out this is much simpler than talked about here in the "answers". Not sure if this works on the iPhone, but I just tested it in a command line app:

QTMovie* movie = [QTMovie movieWithFile:@"filename.m4a" error:nil];

NSInteger numChapters = [movie chapterCount];
NSLog(@"Number of Chapters: %d", numChapters);

NSArray* chapterArray = [movie chapters];
for ( NSDictionary* chapDict in chapterArray )
{
    NSLog(@"%@", [chapDict objectForKey:@"QTMovieChapterName"] );
}

Easy as pie. DOH!

like image 26
pj4533 Avatar answered Nov 15 '22 13:11

pj4533