mirror of
https://github.com/mpv-player/mpv
synced 2025-03-31 15:59:34 +00:00
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.
This commit is contained in:
parent
95a5624946
commit
1cebd16350
@ -247,6 +247,10 @@ Playback Control
|
||||
Note: a playlist can be as simple as a text file containing filenames
|
||||
separated by newlines.
|
||||
|
||||
``--chapters-file=<filename>``
|
||||
Load chapters from this file, instead of using the chapter metadata found
|
||||
in the main file.
|
||||
|
||||
``--sstep=<sec>``
|
||||
Skip <sec> seconds after every frame.
|
||||
|
||||
|
@ -497,6 +497,8 @@ const m_option_t mp_opts[] = {
|
||||
|
||||
OPT_DOUBLE("chapter-seek-threshold", chapter_seek_threshold, 0),
|
||||
|
||||
OPT_STRING("chapters-file", chapter_file, M_OPT_FILE),
|
||||
|
||||
OPT_FLAG("load-unsafe-playlists", load_unsafe_playlists, 0),
|
||||
OPT_FLAG("merge-files", merge_files, 0),
|
||||
|
||||
|
@ -118,6 +118,7 @@ typedef struct MPOpts {
|
||||
char *ordered_chapters_files;
|
||||
int chapter_merge_threshold;
|
||||
double chapter_seek_threshold;
|
||||
char *chapter_file;
|
||||
int load_unsafe_playlists;
|
||||
int merge_files;
|
||||
int quiet;
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user