summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-11-02 16:47:23 +0100
committerwm4 <wm4@nowhere>2014-11-02 17:23:04 +0100
commit1cebd16350229d2ab1441f5061079ce9240fb22f (patch)
tree8e6ca8870280780b309ed0ce8d7bbb9048fc7c48 /player
parent95a5624946f3a6be3c7b79badebf1829f4633539 (diff)
downloadmpv-1cebd16350229d2ab1441f5061079ce9240fb22f.tar.bz2
mpv-1cebd16350229d2ab1441f5061079ce9240fb22f.tar.xz
player: add --chapters-file option
Note that you can't pass .cue or .edl files to it, at least not yet. Requested in context of allowing to specify custom chapters. For that to work well, we probably need to add some sort of chapter metadata pseudo-demuxer.
Diffstat (limited to 'player')
-rw-r--r--player/loadfile.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/player/loadfile.c b/player/loadfile.c
index c4ddf51cc5..a7905a8a36 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -779,20 +779,40 @@ static void print_timeline(struct MPContext *mpctx)
static void load_chapters(struct MPContext *mpctx)
{
- if (!mpctx->chapters && mpctx->master_demuxer &&
- mpctx->master_demuxer->num_chapters)
- {
- int count = mpctx->master_demuxer->num_chapters;
+ struct demuxer *src = mpctx->master_demuxer;
+ bool free_src = false;
+ char *chapter_file = mpctx->opts->chapter_file;
+ if (chapter_file && chapter_file[0]) {
+ struct stream *stream = stream_create(chapter_file, STREAM_READ,
+ mpctx->playback_abort, mpctx->global);
+ if (stream) {
+ struct demuxer *demux = demux_open(stream, NULL, NULL, mpctx->global);
+ if (demux) {
+ src = demux;
+ free_src = true;
+ }
+ }
+ talloc_free(mpctx->chapters);
+ mpctx->chapters = NULL;
+ }
+ if (src && !mpctx->chapters) {
+ talloc_free(mpctx->chapters);
+ int count = src->num_chapters;
mpctx->chapters = talloc_array(NULL, struct chapter, count);
mpctx->num_chapters = count;
for (int n = 0; n < count; n++) {
- struct demux_chapter *dchapter = &mpctx->master_demuxer->chapters[n];
+ struct demux_chapter *dchapter = &src->chapters[n];
mpctx->chapters[n] = (struct chapter){
.start = dchapter->start / 1e9,
.name = talloc_strdup(mpctx->chapters, dchapter->name),
};
}
}
+ if (free_src) {
+ struct stream *s = src->stream;
+ free_demuxer(src);
+ free_stream(s);
+ }
}
static void load_per_file_options(m_config_t *conf,