1
0
Fork 0

get accurate estimate from the PTSes

This commit is contained in:
Cory Fields 2010-07-09 16:47:58 -04:00 committed by Hendrik Leppkes
parent b1c2fb165b
commit d1c56f590c
Signed by: hendrik
GPG Key ID: 846079A4B0A7C1B5
1 changed files with 42 additions and 0 deletions

View File

@ -1974,6 +1974,43 @@ static const char *duration_estimate_name(enum AVDurationEstimationMethod method
return duration_name[method];
}
static void estimate_timings_from_pts2(AVFormatContext *ic, int64_t old_offset)
{
AVStream *st;
int i, step= 1024;
int64_t ts, pos;
for(i=0;i<ic->nb_streams;i++) {
st = ic->streams[i];
pos = 0;
ts = ic->iformat->read_timestamp(ic, i, &pos, DURATION_MAX_READ_SIZE);
if (ts == AV_NOPTS_VALUE)
continue;
if (st->start_time == AV_NOPTS_VALUE ||
st->start_time > ts)
st->start_time = ts;
pos = avio_size(ic->pb) - 1;
do {
pos -= step;
ts = ic->iformat->read_timestamp(ic, i, &pos, pos + step);
step += step;
} while (ts == AV_NOPTS_VALUE && pos >= step && step < DURATION_MAX_READ_SIZE);
if (ts == AV_NOPTS_VALUE)
continue;
if (st->duration == AV_NOPTS_VALUE
|| st->duration < ts - st->start_time)
st->duration = ts - st->start_time;
}
fill_all_stream_timings(ic);
avio_seek(ic->pb, old_offset, SEEK_SET);
}
static void estimate_timings(AVFormatContext *ic, int64_t old_offset)
{
int64_t file_size;
@ -2001,6 +2038,11 @@ static void estimate_timings(AVFormatContext *ic, int64_t old_offset)
ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS;
else
ic->duration_estimation_method = AVFMT_DURATION_FROM_STREAM;
} else if (ic->iformat->read_timestamp &&
file_size && ic->pb->seekable) {
/* get accurate estimate from the PTSes */
estimate_timings_from_pts2(ic, old_offset);
ic->duration_estimation_method = AVFMT_DURATION_FROM_PTS;
} else {
/* less precise: use bitrate info */
estimate_timings_from_bit_rate(ic);