mirror of
https://github.com/mpv-player/mpv
synced 2024-12-26 00:42:57 +00:00
options: support chapters for --start and --end
The --start and --end switch now accept a chapter number. The chapter number is prefixed with '#', e.g. "--start=#2" jumps to chapter 2. The chapter support might be able to replace --chapter completely, but for now I am not sure how well this works out with e.g. DVDs and BDs, and a separate --chapter option is useful interface-wise. (This was supposed to be added in 51503a, but apparently the fixup commit adding it was lost in a rebase. This might also be the reason for the mess-up fixed in 394285.)
This commit is contained in:
parent
39428525c3
commit
f5e2ee5138
@ -1703,7 +1703,9 @@
|
||||
The general format for absolute times is ``[[hh:]mm:]ss[.ms]``. If the time
|
||||
is negated with ``-``, the seek is relative from the end of the file.
|
||||
|
||||
It's also possible to seek to a percent position with ``pp%``.
|
||||
``pp%`` seeks to percent position pp (0-100).
|
||||
|
||||
``#c`` seeks to chapter number c. (Chapters start from 1.)
|
||||
|
||||
*EXAMPLE*:
|
||||
|
||||
@ -1718,6 +1720,8 @@
|
||||
``--start=-3:20 --length=10``
|
||||
Seeks to 3 minutes and 20 seconds before the end of the file, plays
|
||||
10 seconds, and exits.
|
||||
``--start=#2 --end=#4``
|
||||
Plays chapters 2 and 3, and exits.
|
||||
|
||||
--ssf=<mode>
|
||||
Specifies software scaler parameters.
|
||||
|
@ -1268,6 +1268,16 @@ static int parse_rel_time(const m_option_t *opt, struct bstr name,
|
||||
}
|
||||
}
|
||||
|
||||
// Chapter pos
|
||||
if (bstr_startswith0(param, "#")) {
|
||||
int chapter = bstrtoll(bstr_cut(param, 1), ¶m, 10);
|
||||
if (param.len == 0 && chapter >= 1) {
|
||||
t.type = REL_TIME_CHAPTER;
|
||||
t.pos = chapter - 1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
bool sign = bstr_eatstart0(¶m, "-");
|
||||
double time;
|
||||
if (parse_timestring(param, &time, 0)) {
|
||||
@ -1277,7 +1287,7 @@ static int parse_rel_time(const m_option_t *opt, struct bstr name,
|
||||
}
|
||||
|
||||
mp_msg(MSGT_CFGPARSER, MSGL_ERR,
|
||||
"Option %.*s: invalid time or size: '%.*s'\n",
|
||||
"Option %.*s: invalid time or position: '%.*s'\n",
|
||||
BSTR_P(name), BSTR_P(param));
|
||||
return M_OPT_INVALID;
|
||||
|
||||
|
@ -63,6 +63,7 @@ enum m_rel_time_type {
|
||||
REL_TIME_ABSOLUTE,
|
||||
REL_TIME_NEGATIVE,
|
||||
REL_TIME_PERCENT,
|
||||
REL_TIME_CHAPTER,
|
||||
};
|
||||
|
||||
struct m_rel_time {
|
||||
|
@ -270,6 +270,10 @@ static double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t,
|
||||
if (length != 0)
|
||||
return length * (t.pos / 100.0);
|
||||
break;
|
||||
case REL_TIME_CHAPTER:
|
||||
if (chapter_start_time(mpctx, t.pos) >= 0)
|
||||
return chapter_start_time(mpctx, t.pos);
|
||||
break;
|
||||
}
|
||||
return fallback_time;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user