1 From c57e5b8154f5fe1457f4c64e04885a2cdfb37f51 Mon Sep 17 00:00:00 2001
2 From: Joakim Plate <elupus@ecce.se>
3 Date: Sat, 22 Oct 2011 19:01:38 +0200
4 Subject: [PATCH 08/13] Get stream durations using read_timestamp
6 Patch part of the XBMC patch set for ffmpeg, downloaded from
7 https://github.com/xbmc/FFmpeg/.
9 Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
10 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
12 libavformat/utils.c | 39 +++++++++++++++++++++++++++++++++++++++
13 1 file changed, 39 insertions(+)
15 diff --git a/libavformat/utils.c b/libavformat/utils.c
16 index 3e8af50..f4fb172 100644
17 --- a/libavformat/utils.c
18 +++ b/libavformat/utils.c
19 @@ -2356,6 +2356,41 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic)
20 #define DURATION_MAX_READ_SIZE 250000LL
21 #define DURATION_MAX_RETRY 4
23 +static void av_estimate_timings_from_pts2(AVFormatContext *ic, int64_t old_offset)
29 + for(i=0;i<ic->nb_streams;i++) {
30 + st = ic->streams[i];
33 + ts = ic->iformat->read_timestamp(ic, i, &pos, DURATION_MAX_READ_SIZE);
34 + if (ts == AV_NOPTS_VALUE)
36 + if (st->start_time > ts || st->start_time == AV_NOPTS_VALUE)
37 + st->start_time = ts;
39 + pos = avio_size(ic->pb) - 1;
42 + ts = ic->iformat->read_timestamp(ic, i, &pos, pos + step);
44 + } while (ts == AV_NOPTS_VALUE && pos >= step && step < DURATION_MAX_READ_SIZE);
46 + if (ts == AV_NOPTS_VALUE)
49 + if (st->duration < ts - st->start_time || st->duration == AV_NOPTS_VALUE)
50 + st->duration = ts - st->start_time;
53 + fill_all_stream_timings(ic);
55 + avio_seek(ic->pb, old_offset, SEEK_SET);
58 /* only usable for MPEG-PS streams */
59 static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
61 @@ -2506,6 +2541,10 @@ static void estimate_timings(AVFormatContext *ic, int64_t old_offset)
63 fill_all_stream_timings(ic);
64 ic->duration_estimation_method = AVFMT_DURATION_FROM_STREAM;
65 + } else if (ic->iformat->read_timestamp &&
66 + file_size && ic->pb->seekable) {
67 + /* get accurate estimate from the PTSes */
68 + av_estimate_timings_from_pts2(ic, old_offset);
70 /* less precise: use bitrate info */
71 estimate_timings_from_bit_rate(ic);