diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-05-16 16:13:36 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-05-16 16:13:36 +0200 |
commit | 77a0df4b5e3829d0cde880d3f39d618211cb9a6d (patch) | |
tree | bde2fd2612f39e4b8d7551406e358b3e6cb83896 | |
parent | 68cea1bc8eb194b682eb1dcef04a97d6dfc4ca0d (diff) | |
download | ffmpeg-77a0df4b5e3829d0cde880d3f39d618211cb9a6d.tar.gz |
estimate_timings_from_pts: Execute max 1 iteration extra to find more than 1 duration
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/utils.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c index 604408f8f4..6454421d7d 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2469,7 +2469,8 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) AVPacket pkt1, *pkt = &pkt1; AVStream *st; int read_size, i, ret; - int all_duration_valid = 0; + int found_duration = 0; + int is_end; int64_t filesize, offset, duration; int retry = 0; @@ -2494,6 +2495,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) /* XXX: may need to support wrapping */ filesize = ic->pb ? avio_size(ic->pb) : 0; do { + is_end = found_duration; offset = filesize - (DURATION_MAX_READ_SIZE << retry); if (offset < 0) offset = 0; @@ -2515,6 +2517,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) (st->start_time != AV_NOPTS_VALUE || st->first_dts != AV_NOPTS_VALUE)) { duration = pkt->pts + pkt->duration; + found_duration = 1; if (st->start_time != AV_NOPTS_VALUE) duration -= st->start_time; else @@ -2530,17 +2533,19 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) } /* check if all audio/video streams have valid duration */ - all_duration_valid = 1; - for (i = 0; i < ic->nb_streams; i++) { - st = ic->streams[i]; - switch (st->codec->codec_type) { - case AVMEDIA_TYPE_VIDEO: - case AVMEDIA_TYPE_AUDIO: - if (st->duration == AV_NOPTS_VALUE) - all_duration_valid = 0; + if (!is_end) { + is_end = 1; + for (i = 0; i < ic->nb_streams; i++) { + st = ic->streams[i]; + switch (st->codec->codec_type) { + case AVMEDIA_TYPE_VIDEO: + case AVMEDIA_TYPE_AUDIO: + if (st->duration == AV_NOPTS_VALUE) + is_end = 0; + } } } - } while (!all_duration_valid && + } while (!is_end && offset && ++retry <= DURATION_MAX_RETRY); |