diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-05-06 20:27:20 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2022-05-10 07:42:07 +0200 |
commit | ff0e8e14c3e9d1003153324d0368735dd84cb4b7 (patch) | |
tree | 23d2efbf83f17295cc44a50ef28bfa3d28009ac7 /libavformat/demux_utils.c | |
parent | 8550a05ece37cbb777deb221cce43b5f3345137b (diff) | |
download | ffmpeg-ff0e8e14c3e9d1003153324d0368735dd84cb4b7.tar.gz |
avformat/utils: Move avpriv_new_chapter to demux_utils.c
It is demuxer-only: Muxers deal only with chapters given to them;
they don't create any of their own.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/demux_utils.c')
-rw-r--r-- | libavformat/demux_utils.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/libavformat/demux_utils.c b/libavformat/demux_utils.c index 10ae887359..cfd6084d54 100644 --- a/libavformat/demux_utils.c +++ b/libavformat/demux_utils.c @@ -32,3 +32,44 @@ void avpriv_stream_set_need_parsing(AVStream *st, enum AVStreamParseType type) { ffstream(st)->need_parsing = type; } + +AVChapter *avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, + int64_t start, int64_t end, const char *title) +{ + FFFormatContext *const si = ffformatcontext(s); + AVChapter *chapter = NULL; + int ret; + + if (end != AV_NOPTS_VALUE && start > end) { + av_log(s, AV_LOG_ERROR, "Chapter end time %"PRId64" before start %"PRId64"\n", end, start); + return NULL; + } + + if (!s->nb_chapters) { + si->chapter_ids_monotonic = 1; + } else if (!si->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) { + for (unsigned i = 0; i < s->nb_chapters; i++) + if (s->chapters[i]->id == id) + chapter = s->chapters[i]; + if (!chapter) + si->chapter_ids_monotonic = 0; + } + + if (!chapter) { + chapter = av_mallocz(sizeof(*chapter)); + if (!chapter) + return NULL; + ret = av_dynarray_add_nofree(&s->chapters, &s->nb_chapters, chapter); + if (ret < 0) { + av_free(chapter); + return NULL; + } + } + av_dict_set(&chapter->metadata, "title", title, 0); + chapter->id = id; + chapter->time_base = time_base; + chapter->start = start; + chapter->end = end; + + return chapter; +} |