options: support setting start time relative to start PTS

Signed-off-by: wm4 <wm4@nowhere>
This commit is contained in:
Tsukasa OMOTO 2014-06-30 02:44:32 +09:00 committed by wm4
parent a73415584c
commit 1aef780b6c
4 changed files with 20 additions and 9 deletions

View File

@ -2133,7 +2133,8 @@ OPTIONS
Seek to given time position.
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.
is given with a prefix of ``+`` or ``-``, the seek is relative from the start
or end of the file.
``pp%`` seeks to percent position pp (0-100).
@ -2141,8 +2142,10 @@ OPTIONS
.. admonition:: Examples
``--start=56``
Seeks to 56 seconds.
``--start=+56``, ``--start=+00:56``
Seeks to the start time + 56 seconds.
``--start=-56``, ``--start=-00:56``
Seeks to the end time - 56 seconds.
``--start=01:10:00``
Seeks to 1 hour 10 min.
``--start=50%``

View File

@ -2181,10 +2181,13 @@ static int parse_rel_time(struct mp_log *log, const m_option_t *opt,
}
}
bool sign = bstr_eatstart0(&param, "-");
double time;
if (parse_timestring(param, &time, 0)) {
t.type = sign ? REL_TIME_NEGATIVE : REL_TIME_ABSOLUTE;
if (bstr_startswith0(param, "+") || bstr_startswith0(param, "-")) {
t.type = REL_TIME_RELATIVE;
} else {
t.type = REL_TIME_ABSOLUTE;
}
t.pos = time;
goto out;
}

View File

@ -70,7 +70,7 @@ typedef void (*m_opt_print_fn)(struct mp_log *log);
enum m_rel_time_type {
REL_TIME_NONE,
REL_TIME_ABSOLUTE,
REL_TIME_NEGATIVE,
REL_TIME_RELATIVE,
REL_TIME_PERCENT,
REL_TIME_CHAPTER,
};

View File

@ -53,12 +53,17 @@ double get_relative_time(struct MPContext *mpctx)
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t)
{
double length = get_time_length(mpctx);
double start = get_start_time(mpctx);
switch (t.type) {
case REL_TIME_ABSOLUTE:
return t.pos;
case REL_TIME_NEGATIVE:
if (length != 0)
return MPMAX(length - t.pos, 0.0);
case REL_TIME_RELATIVE:
if (t.pos >= 0) {
return start + t.pos;
} else {
if (length != 0)
return MPMAX(start + length + t.pos, 0.0);
}
break;
case REL_TIME_PERCENT:
if (length != 0)