You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
lavf: make compute_chapters_end less picky.
In particular, now it assumes that a) chapters are chronologically ordered b) chapters have the same timebases c) duration of the stream is known and asserts if any of these is not met. Make it properly deal with harsher conditions. fixes issue2320
This commit is contained in:
@@ -2168,21 +2168,22 @@ enum CodecID av_codec_get_id(const AVCodecTag * const *tags, unsigned int tag)
|
|||||||
|
|
||||||
static void compute_chapters_end(AVFormatContext *s)
|
static void compute_chapters_end(AVFormatContext *s)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i, j;
|
||||||
|
int64_t max_time = s->duration + (s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time;
|
||||||
|
|
||||||
for (i=0; i+1<s->nb_chapters; i++)
|
for (i = 0; i < s->nb_chapters; i++)
|
||||||
if (s->chapters[i]->end == AV_NOPTS_VALUE) {
|
if (s->chapters[i]->end == AV_NOPTS_VALUE) {
|
||||||
assert(s->chapters[i]->start <= s->chapters[i+1]->start);
|
AVChapter *ch = s->chapters[i];
|
||||||
assert(!av_cmp_q(s->chapters[i]->time_base, s->chapters[i+1]->time_base));
|
int64_t end = max_time ? av_rescale_q(max_time, AV_TIME_BASE_Q, ch->time_base)
|
||||||
s->chapters[i]->end = s->chapters[i+1]->start;
|
: INT64_MAX;
|
||||||
}
|
|
||||||
|
|
||||||
if (s->nb_chapters && s->chapters[i]->end == AV_NOPTS_VALUE) {
|
for (j = 0; j < s->nb_chapters; j++) {
|
||||||
assert(s->start_time != AV_NOPTS_VALUE);
|
AVChapter *ch1 = s->chapters[j];
|
||||||
assert(s->duration > 0);
|
int64_t next_start = av_rescale_q(ch1->start, ch1->time_base, ch->time_base);
|
||||||
s->chapters[i]->end = av_rescale_q(s->start_time + s->duration,
|
if (j != i && next_start > ch->start && next_start < end)
|
||||||
AV_TIME_BASE_Q,
|
end = next_start;
|
||||||
s->chapters[i]->time_base);
|
}
|
||||||
|
ch->end = (end == INT64_MAX) ? ch->start : end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user