diff options
author | Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com> | 2020-09-09 17:48:45 +0300 |
---|---|---|
committer | wm4 <1387750+wm4@users.noreply.github.com> | 2020-09-17 10:34:57 +0200 |
commit | b959a2229176a98ba83c196ad32cad538520c3aa (patch) | |
tree | 5bdff0892b3d3971eb73b44ec8b67584ae2b682a | |
parent | 49f5c9b4820b082b8d25b753ff010562939a754f (diff) | |
download | mpv-b959a2229176a98ba83c196ad32cad538520c3aa.tar.bz2 mpv-b959a2229176a98ba83c196ad32cad538520c3aa.tar.xz |
stream_slice: interpret `end` as offset if it starts with '+'
Example:
slice://1g-2g@file.ts (1 to 2)
slice://1g-+2g@file.ts (1 to 3)
Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
-rw-r--r-- | DOCS/man/mpv.rst | 7 | ||||
-rw-r--r-- | stream/stream_slice.c | 4 |
2 files changed, 11 insertions, 0 deletions
diff --git a/DOCS/man/mpv.rst b/DOCS/man/mpv.rst index 09c3e24ea6..7b1c48c4a2 100644 --- a/DOCS/man/mpv.rst +++ b/DOCS/man/mpv.rst @@ -1208,6 +1208,8 @@ PROTOCOLS ``start`` and ``end`` represent a byte range and accept suffixes such as ``KiB`` and ``MiB``. ``end`` is optional. + if ``end`` starts with ``+``, it is considered as offset from ``start``. + Only works with seekable streams. Examples:: @@ -1217,6 +1219,11 @@ PROTOCOLS This starts reading from cap.ts after seeking 1 GiB, then reads until reaching 2 GiB or end of file. + mpv slice://1g-+2g@cap.ts + + This starts reading from cap.ts after seeking 1 GiB, then + reads until reaching 3 GiB or end of file. + mpv slice://100m@appending://cap.ts This starts reading from cap.ts after seeking 100MiB, then diff --git a/stream/stream_slice.c b/stream/stream_slice.c index 7889c8d059..d7d0a6bf05 100644 --- a/stream/stream_slice.c +++ b/stream/stream_slice.c @@ -116,11 +116,15 @@ static int parse_slice_range(stream_t *stream) if (m_option_parse(stream->log, &opt, bstr0("slice_start"), start, &p->slice_start) < 0) return STREAM_ERROR; + bool max_end_is_offset = bstr_startswith0(end, "+"); if (has_end) { if (m_option_parse(stream->log, &opt, bstr0("slice_max_end"), end, &p->slice_max_end) < 0) return STREAM_ERROR; } + if (max_end_is_offset) + p->slice_max_end += p->slice_start; + if (p->slice_max_end && p->slice_max_end < p->slice_start) { MP_ERR(stream, "The byte range end (%"PRId64") can't be smaller than the start (%"PRId64"): '%s'\n", p->slice_max_end, |