Mercurial > libavformat.hg
changeset 5454:01cad9ef4a57 libavformat
Try to simplify av_estimate_timings_from_pts() like in ffmbc.
Note if this breaks for some file, report it please!
author | michael |
---|---|
date | Sun, 13 Dec 2009 22:56:59 +0000 |
parents | 39e5af193378 |
children | df772456ed85 |
files | utils.c |
diffstat | 1 files changed, 10 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/utils.c Sun Dec 13 22:31:29 2009 +0000 +++ b/utils.c Sun Dec 13 22:56:59 2009 +0000 @@ -1758,7 +1758,7 @@ AVPacket pkt1, *pkt = &pkt1; AVStream *st; int read_size, i, ret; - int64_t end_time; + int64_t end_time, start_time[MAX_STREAMS]; int64_t filesize, offset, duration; ic->cur_st = NULL; @@ -1768,6 +1768,13 @@ for(i=0;i<ic->nb_streams;i++) { st = ic->streams[i]; + if(st->start_time != AV_NOPTS_VALUE){ + start_time[i]= st->start_time; + }else if(st->first_dts != AV_NOPTS_VALUE){ + start_time[i]= st->first_dts; + }else + av_log(st->codec, AV_LOG_WARNING, "start time is not set in av_estimate_timings_from_pts\n"); + if (st->parser) { av_parser_close(st->parser); st->parser= NULL; @@ -1775,36 +1782,6 @@ } } - /* we read the first packets to get the first PTS (not fully - accurate, but it is enough now) */ - url_fseek(ic->pb, 0, SEEK_SET); - read_size = 0; - for(;;) { - if (read_size >= DURATION_MAX_READ_SIZE) - break; - /* if all info is available, we can stop */ - for(i = 0;i < ic->nb_streams; i++) { - st = ic->streams[i]; - if (st->start_time == AV_NOPTS_VALUE) - break; - } - if (i == ic->nb_streams) - break; - - do{ - ret = av_read_packet(ic, pkt); - }while(ret == AVERROR(EAGAIN)); - if (ret != 0) - break; - read_size += pkt->size; - st = ic->streams[pkt->stream_index]; - if (pkt->pts != AV_NOPTS_VALUE) { - if (st->start_time == AV_NOPTS_VALUE) - st->start_time = pkt->pts; - } - av_free_packet(pkt); - } - /* estimate the end time (duration) */ /* XXX: may need to support wrapping */ filesize = ic->file_size; @@ -1826,9 +1803,9 @@ read_size += pkt->size; st = ic->streams[pkt->stream_index]; if (pkt->pts != AV_NOPTS_VALUE && - st->start_time != AV_NOPTS_VALUE) { + start_time[pkt->stream_index] != AV_NOPTS_VALUE) { end_time = pkt->pts; - duration = end_time - st->start_time; + duration = end_time - start_time[pkt->stream_index]; if (duration > 0) { if (st->duration == AV_NOPTS_VALUE || st->duration < duration)