diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index c743a2a6fa..24307c3cae 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -4242,7 +4242,8 @@ static int seek_to_start(InputFile *ifile, AVFormatContext *is) ifile->time_base = ist->st->time_base; /* the total duration of the stream, max_pts - min_pts is * the duration of the stream without the last frame */ - duration += ist->max_pts - ist->min_pts; + if (ist->max_pts > ist->min_pts && ist->max_pts - (uint64_t)ist->min_pts < INT64_MAX - duration) + duration += ist->max_pts - ist->min_pts; ifile->time_base = duration_max(duration, &ifile->duration, ist->st->time_base, ifile->time_base); }