player/misc.c: allow both --length and --end to control play endpoint

Most options that change the playback endpoint coexist and playback
stops when it reaches any of them. (e.g. --ab-loop-b, --end, or
--chapter). This patch extends that behavior to --length so it isn't
automatically trumped by --end if both are present. These two will
interact now as the other options do.

This change is also documented in DOCS/man/options.rst.
This commit is contained in:
Leo Izen 2017-12-04 12:30:22 -05:00
parent 9abb710afb
commit fdc311625e
2 changed files with 6 additions and 2 deletions

View File

@ -133,6 +133,9 @@ Playback Control
Stop after a given time relative to the start time.
See ``--start`` for valid option values and examples.
If both ``--end`` and ``--length`` are provided, playback will stop when it
reaches either of the two endpoints.
``--rebase-start-time=<yes|no>``
Whether to move the file start time to ``00:00:00`` (default: yes). This
is less awkward for files which start at a random timestamp, such as

View File

@ -91,12 +91,13 @@ double get_play_end_pts(struct MPContext *mpctx)
double end = MP_NOPTS_VALUE;
if (opts->play_end.type) {
end = rel_time_to_abs(mpctx, opts->play_end);
} else if (opts->play_length.type) {
}
if (opts->play_length.type) {
double start = get_play_start_pts(mpctx);
if (start == MP_NOPTS_VALUE)
start = 0;
double length = rel_time_to_abs(mpctx, opts->play_length);
if (length != MP_NOPTS_VALUE)
if (length != MP_NOPTS_VALUE && (end == MP_NOPTS_VALUE || start + length < end))
end = start + length;
}
if (opts->chapterrange[1] > 0) {