summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorGaullier Nicolas <nicolas.gaullier@arkena.com>2014-05-14 16:25:13 +0000
committerMichael Niedermayer <michaelni@gmx.at>2014-05-16 16:06:55 +0200
commit68cea1bc8eb194b682eb1dcef04a97d6dfc4ca0d (patch)
tree1b66a1df6a1735670a0564572a88a8455b4cbfc3 /libavformat
parent424599c7cc723ccf6b0b7976d87dd220fffa8934 (diff)
estimate_timings_from_pts: Try to get the duration for all streams
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/utils.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 4248c8c27a..604408f8f4 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2469,7 +2469,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
AVPacket pkt1, *pkt = &pkt1;
AVStream *st;
int read_size, i, ret;
- int64_t end_time;
+ int all_duration_valid = 0;
int64_t filesize, offset, duration;
int retry = 0;
@@ -2493,7 +2493,6 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
/* estimate the end time (duration) */
/* XXX: may need to support wrapping */
filesize = ic->pb ? avio_size(ic->pb) : 0;
- end_time = AV_NOPTS_VALUE;
do {
offset = filesize - (DURATION_MAX_READ_SIZE << retry);
if (offset < 0)
@@ -2515,7 +2514,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
if (pkt->pts != AV_NOPTS_VALUE &&
(st->start_time != AV_NOPTS_VALUE ||
st->first_dts != AV_NOPTS_VALUE)) {
- duration = end_time = pkt->pts + pkt->duration;
+ duration = pkt->pts + pkt->duration;
if (st->start_time != AV_NOPTS_VALUE)
duration -= st->start_time;
else
@@ -2529,7 +2528,19 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
}
av_free_packet(pkt);
}
- } while (end_time == AV_NOPTS_VALUE &&
+
+ /* 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;
+ }
+ }
+ } while (!all_duration_valid &&
offset &&
++retry <= DURATION_MAX_RETRY);