1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Try to simplify av_estimate_timings_from_pts() like in ffmbc.

Note if this breaks for some file, report it please!

Originally committed as revision 20844 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
Michael Niedermayer 2009-12-13 22:56:59 +00:00
parent 35164ffe50
commit cc20679a41

View File

@ -1758,7 +1758,7 @@ static void av_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;
int64_t end_time, start_time[MAX_STREAMS];
int64_t filesize, offset, duration;
ic->cur_st = NULL;
@ -1768,6 +1768,13 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset
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 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset
}
}
/* 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 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset
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)