diff options
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r-- | libavformat/utils.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c index 66f26ccd6e..aa8a117c23 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2234,18 +2234,29 @@ void av_set_program_name(AVProgram *program, char *provider_name, char *name) } } -int ff_new_chapter(AVFormatContext *s, int64_t start, int64_t end, const char *title) +int ff_new_chapter(AVFormatContext *s, int id, int64_t start, int64_t end, const char *title) { - AVChapter *chapter = av_mallocz(sizeof(AVChapter)); + AVChapter *chapter = NULL; + int i; + + for(i=0; i<s->num_chapters; i++) + if(s->chapters[i]->id == id) + chapter = s->chapters[i]; + + if(!chapter){ + chapter= av_mallocz(sizeof(AVChapter)); if(!chapter) return AVERROR(ENOMEM); + dynarray_add(&s->chapters, &s->num_chapters, chapter); + } + if(chapter->title) + av_free(chapter->title); if (title) chapter->title = av_strdup(title); + chapter->id = id; chapter->start = start; chapter->end = end; - dynarray_add(&s->chapters, &s->num_chapters, chapter); - return 0; } |