This is regarding the bug: https://bugs.kde.org/show_bug.cgi?id=240409
The file attached decodes m4b files and displays the chapter markers and the time. To compile it please install the "libmp4v2-dev" package ( add option -lmp4v2 while compiling ). For this to work I need the file path and file name, but the Meta::TrackPtr class provides everything but that information. Here are questions I really need help with answering How can I obtain the filepath and filename? One of the comments previously mentioned that mp4v2 was removed, so it is possible for me to add it back again? or should I program the offset calculation for the chapters myself? If it is okay to add, How do i add?
#include <mp4v2/mp4v2.h> #include <stdio.h> /* * format a duration to a readable format ("stolen" from gpac MP4Box) */ static char *format_duration(uint64_t dur, char *szDur) { uint32_t h, m, s, ms; h = (uint32_t) (dur / 3600000); m = (uint32_t) (dur / 60000) - h * 60; s = (uint32_t) (dur / 1000) - h * 3600 - m * 60; ms = (uint32_t) (dur) - h * 3600000 - m * 60000 - s * 1000; if (h<=24) { sprintf(szDur, "%02d:%02d:%02d.%03d", h, m, s, ms); } else { uint32_t d = (uint32_t) (dur / 3600000 / 24); h = (uint32_t) (dur/3600000)-24*d; if (d<=365) { sprintf(szDur, "%d Days, %02d:%02d:%02d.%03d", d, h, m, s, ms); } else { uint32_t y=0; while (d>365) { y++; d-=365; if (y%4) d--; } sprintf(szDur, "%d Years %d Days, %02d:%02d:%02d.%03d", y, d, h, m, s, ms); } } return szDur; } /* * List chapter start time and title */ void ListChapters(MP4FileHandle hFile, MP4ChapterType fromChapterType) { MP4Chapter_t * chapters = 0; uint32_t chapterCount = 0; char szDur[20] = {0}; MP4Duration durationSum = 0; // get the list of chapters MP4ChapterType type = MP4GetChapters(hFile, &chapters, &chapterCount, fromChapterType); if (0 == chapterCount) { return; } // start output (in mp4box format) switch(type) { case MP4ChapterTypeQt: fprintf(stdout, "\nQuickTime"); break; case MP4ChapterTypeNero: fprintf(stdout, "\nNero"); break; default: fprintf(stdout, "\nUnknown"); } fprintf(stdout, " Chapters:\n"); for (uint32_t i = 0; i < chapterCount; ++i) { // get the tile const char * title = chapters[i].title; // format the start time const char * formattedDuration = format_duration(durationSum, szDur); // print the infos fprintf(stdout, "\tChapter #%u - %s - \"%s\"\n", i+1, formattedDuration, title); // add the duration of this chapter to the sum (is the start time of the next chapter) durationSum += chapters[i].duration; } // free up the memory MP4Free(chapters); } int main(int argc,char** argv) { MP4FileHandle h = 0; MP4ChapterType chapterType = MP4ChapterTypeAny; h = MP4Read(argv[1]); if (h == MP4_INVALID_FILE_HANDLE) { printf("Could not open '%s'... aborting\n",argv[1]); return -1; } ListChapters(h, chapterType); return 0; }
_______________________________________________ Amarok-devel mailing list Amarok-devel@kde.org https://mail.kde.org/mailman/listinfo/amarok-devel