edl: extend with chapter timestamps

Example see edl-mpv.rst.

What is this useful for? No clue...
This commit is contained in:
wm4 2014-02-19 00:06:00 +01:00
parent d29661af8a
commit e6f543ebec
2 changed files with 38 additions and 1 deletions

View File

@ -78,7 +78,7 @@ The parameter name defines the meaning of the parameter:
2) ``start``, a time value that specifies the start offset into the source file.
3) ``length``, a time value that specifies the length of the segment.
(Currently, time values are floating point values in seconds.)
See the section below for the format of timestamps.
Unnamed parameters carry implicit names. The parameter position determines
which of the parameters listed above is set. For example, the second parameter
@ -95,6 +95,22 @@ to ``20``, ``param3`` to ``value,escaped``, ``param4`` to ``value2``.
Instead of line breaks, the character ``;`` can be used. Line feed bytes and
``;`` are treated equally.
Timestamp format
================
Currently, time values are floating point values in seconds.
As an extension, you can set the ``timestamps=chapters`` option. If this option
is set, timestamps have to be integers, and refer to chapter numbers, starting
with 0.
Example::
# mpv EDL v0
file.mkv,2,4,timestamps=chapters
Plays chapter 3 and ends with the start of chapter 7 (4 chapters later).
Syntax of EDL URIs
==================

View File

@ -36,6 +36,7 @@ struct tl_part {
char *filename; // what is stream_open()ed
double offset; // offset into the source file
double length; // length of the part (-1 if rest of the file)
bool chapter_ts;
};
struct tl_parts {
@ -102,6 +103,9 @@ static struct tl_parts *parse_edl(bstr str)
} else if (bstr_equals0(name, "length")) {
if (!parse_time(val, &p.length))
goto error;
} else if (bstr_equals0(name, "timestamps")) {
if (bstr_equals0(val, "chapters"))
p.chapter_ts = true;
}
nparam++;
if (!bstr_eatstart0(&str, ","))
@ -182,6 +186,21 @@ static double source_get_length(struct demuxer *demuxer)
return time;
}
static void resolve_timestamps(struct tl_part *part, struct demuxer *demuxer)
{
if (part->chapter_ts) {
double start = demuxer_chapter_time(demuxer, part->offset);
double length = part->length;
double end = length;
if (end >= 0)
end = demuxer_chapter_time(demuxer, part->offset + part->length);
if (end >= 0 && start >= 0)
length = end - start;
part->offset = start;
part->length = length;
}
}
static void build_timeline(struct MPContext *mpctx, struct tl_parts *parts)
{
struct chapter *chapters = talloc_new(NULL);
@ -195,6 +214,8 @@ static void build_timeline(struct MPContext *mpctx, struct tl_parts *parts)
if (!source)
goto error;
resolve_timestamps(part, source);
double len = source_get_length(source);
if (len <= 0) {
MP_WARN(mpctx, "EDL: source file '%s' has unknown duration.\n",