From 2f49fbff93d76950c441daef76afb3adb9078429 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 14 Dec 2013 21:52:37 +0100 Subject: matroska: add --ordered-chapters-files option This option takes a playlist. The playlist will then be used as list of potential segment files for use with ordered chapters. --- DOCS/man/en/options.rst | 12 ++++++++++++ mpvcore/options.c | 1 + mpvcore/options.h | 1 + mpvcore/player/timeline/tl_matroska.c | 18 ++++++++++++++++-- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst index 584567bc50..9e7f55da2b 100644 --- a/DOCS/man/en/options.rst +++ b/DOCS/man/en/options.rst @@ -1436,6 +1436,18 @@ OPTIONS search for video segments from other files, and will also ignore any chapter order specified for the main file. +``--ordered-chapters-files=`` + Loads the given file as playlist, and tries to use the files contained in + it as reference files when opening a Matroska file that uses ordered + chapters. This overrides the normal mechanism for loading referenced + files by scanning the same directory the main file is located in. + + Useful for loading ordered chapter files that are not located on the local + filesystem, or if the referenced files are in different directories. + + Note: a playlist can be as simple as a text file containing filenames + separated by newlines. + ``--osc``, ``--no-osc`` Whether to load the on-screen-controller (default: yes). diff --git a/mpvcore/options.c b/mpvcore/options.c index de7183014f..1a76aa9bf3 100644 --- a/mpvcore/options.c +++ b/mpvcore/options.c @@ -684,6 +684,7 @@ const m_option_t mp_opts[] = { OPT_FLAG("save-position-on-quit", position_save_on_quit, 0), OPT_FLAG("ordered-chapters", ordered_chapters, 0), + OPT_STRING("ordered-chapters-files", ordered_chapters_files, 0), OPT_INTRANGE("chapter-merge-threshold", chapter_merge_threshold, 0, 0, 10000), OPT_DOUBLE("chapter-seek-threshold", chapter_seek_threshold, 0), diff --git a/mpvcore/options.h b/mpvcore/options.h index f421fcccb5..1544e37edb 100644 --- a/mpvcore/options.h +++ b/mpvcore/options.h @@ -91,6 +91,7 @@ typedef struct MPOpts { int loop_times; int shuffle; int ordered_chapters; + char *ordered_chapters_files; int chapter_merge_threshold; double chapter_seek_threshold; int load_unsafe_playlists; diff --git a/mpvcore/player/timeline/tl_matroska.c b/mpvcore/player/timeline/tl_matroska.c index 2ecc292a84..fa0e315fc5 100644 --- a/mpvcore/player/timeline/tl_matroska.c +++ b/mpvcore/player/timeline/tl_matroska.c @@ -36,6 +36,8 @@ #include "mpvcore/path.h" #include "mpvcore/bstr.h" #include "mpvcore/mp_common.h" +#include "mpvcore/playlist.h" +#include "mpvcore/playlist_parser.h" #include "stream/stream.h" struct find_entry { @@ -250,13 +252,23 @@ static int find_ordered_chapter_sources(struct MPContext *mpctx, int *num_sources, struct matroska_segment_uid **uids) { + struct MPOpts *opts = mpctx->opts; + void *tmp = talloc_new(NULL); int num_filenames = 0; char **filenames = NULL; if (*num_sources > 1) { char *main_filename = mpctx->demuxer->filename; mp_msg(MSGT_CPLAYER, MSGL_INFO, "This file references data from " "other sources.\n"); - if (mpctx->demuxer->stream->uncached_type != STREAMTYPE_FILE) { + if (opts->ordered_chapters_files && opts->ordered_chapters_files[0]) { + mp_msg(MSGT_CPLAYER, MSGL_INFO, "Loading references from '%s'.\n", + opts->ordered_chapters_files); + struct playlist *pl = + playlist_parse_file(opts->ordered_chapters_files, opts); + talloc_steal(tmp, pl); + for (struct playlist_entry *e = pl->first; e; e = e->next) + MP_TARRAY_APPEND(tmp, filenames, num_filenames, e->filename); + } else if (mpctx->demuxer->stream->uncached_type != STREAMTYPE_FILE) { mp_msg(MSGT_CPLAYER, MSGL_WARN, "Playback source is not a " "normal disk file. Will not search for related files.\n"); } else { @@ -264,6 +276,7 @@ static int find_ordered_chapter_sources(struct MPContext *mpctx, "same directory to find referenced sources.\n"); filenames = find_files(main_filename, ".mkv"); num_filenames = MP_TALLOC_ELEMS(filenames); + talloc_steal(tmp, filenames); } // Possibly get further segments appended to the first segment check_file(mpctx, sources, num_sources, uids, main_filename, 1); @@ -281,7 +294,6 @@ static int find_ordered_chapter_sources(struct MPContext *mpctx, /* Loop while we have new sources to look for. */ } while (old_source_count != *num_sources); - talloc_free(filenames); if (missing(*sources, *num_sources)) { mp_msg(MSGT_CPLAYER, MSGL_ERR, "Failed to find ordered chapter part!\n" "There will be parts MISSING from the video!\n"); @@ -296,6 +308,8 @@ static int find_ordered_chapter_sources(struct MPContext *mpctx, } *num_sources = j; } + + talloc_free(tmp); return *num_sources; } -- cgit v1.2.3