From 961e0ccdcaa4fd3a217270ed5da9f2c1efcdf4cc Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 24 Jun 2005 11:43:08 +0000 Subject: [PATCH] another chapter in the neverending mov demuxer cleanup a timebase isnt an average frame rate neither can highlevel (considering edit lists) duration be mixed with lowlevel ones Originally committed as revision 4391 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavformat/mov.c | 58 ++++++++++------------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index c2f7abffa0..24fe60722a 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -652,7 +652,7 @@ static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) #ifdef DEBUG av_log(NULL, AV_LOG_DEBUG, "track[%i].time_scale = %i\n", c->fc->nb_streams-1, c->streams[c->fc->nb_streams-1]->time_scale); /* time scale */ #endif - get_be32(pb); /* duration */ + c->fc->streams[c->fc->nb_streams-1]->duration= get_be32(pb); /* duration */ get_be16(pb); /* language */ get_be16(pb); /* quality */ @@ -1338,44 +1338,20 @@ av_log(NULL, AV_LOG_DEBUG, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, sample_duration = get_be32(pb); c->streams[c->fc->nb_streams - 1]->stts_data[i].count= sample_count; c->streams[c->fc->nb_streams - 1]->stts_data[i].duration= sample_duration; + #ifdef DEBUG av_log(NULL, AV_LOG_DEBUG, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration); #endif duration+=sample_duration*sample_count; total_sample_count+=sample_count; - -#if 0 //We calculate an average instead, needed by .mp4-files created with nec e606 3g phone - - if (!i && st->codec.codec_type==CODEC_TYPE_VIDEO) { - st->codec.time_base.num = sample_duration ? sample_duration : 1; - st->codec.time_base.den = c->streams[c->fc->nb_streams-1]->time_scale; -#ifdef DEBUG - av_log(NULL, AV_LOG_DEBUG, "VIDEO FRAME RATE= %i (sd= %i)\n", st->codec.time_base.den, sample_duration); -#endif - } -#endif } - /*The stsd atom which contain codec type sometimes comes after the stts so we cannot check for codec_type*/ - if(duration>0) - { - av_reduce( - &st->codec.time_base.den, - &st->codec.time_base.num, - c->streams[c->fc->nb_streams-1]->time_scale * total_sample_count, - duration, - INT_MAX - ); - -#ifdef DEBUG - av_log(NULL, AV_LOG_DEBUG, "FRAME RATE average (video or audio)= %f (tot sample count= %i ,tot dur= %i timescale=%d)\n", (float)st->codec.time_base.den/st->codec.time_base.num,total_sample_count,duration,c->streams[c->fc->nb_streams-1]->time_scale); -#endif - } - else - { - st->codec.time_base.num = 1; - st->codec.time_base.den = c->streams[c->fc->nb_streams-1]->time_scale; - } + av_set_pts_info(st, 64, 1, c->streams[c->fc->nb_streams-1]->time_scale); +// st->codec.time_base.num = 1; +// st->codec.time_base.den = c->streams[c->fc->nb_streams-1]->time_scale; + st->nb_frames= total_sample_count; + if(duration) + st->duration= duration; return 0; } @@ -1425,7 +1401,6 @@ static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) st->priv_data = sc; st->codec.codec_type = CODEC_TYPE_MOV_OTHER; st->start_time = 0; /* XXX: check */ - st->duration = (c->duration * (int64_t)AV_TIME_BASE) / c->time_scale; c->streams[c->fc->nb_streams-1] = sc; return mov_read_default(c, pb, atom); @@ -1455,7 +1430,7 @@ static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/ get_be32(pb); /* reserved */ st->start_time = 0; /* check */ - st->duration = (get_be32(pb) * (int64_t)AV_TIME_BASE) / c->time_scale; /* duration */ + get_be32(pb); /* highlevel (considering edits) duration in movie timebase */ get_be32(pb); /* reserved */ get_be32(pb); /* reserved */ @@ -2033,12 +2008,8 @@ readchunk: pts = dts + duration; }else pts = dts; - pkt->pts = av_rescale( pts, - (int64_t)s->streams[sc->ffindex]->time_base.den, - (int64_t)sc->time_scale * (int64_t)s->streams[sc->ffindex]->time_base.num ); - pkt->dts = av_rescale( dts, - (int64_t)s->streams[sc->ffindex]->time_base.den, - (int64_t)sc->time_scale * (int64_t)s->streams[sc->ffindex]->time_base.num ); + pkt->pts = pts; + pkt->dts = dts; #ifdef DEBUG av_log(NULL, AV_LOG_DEBUG, "stream #%d smp #%ld dts = %lld pts = %lld (smp:%ld time:%lld idx:%d ent:%d count:%d dur:%d)\n" , pkt->stream_index, sc->current_sample-1, pkt->dts, pkt->pts @@ -2058,12 +2029,11 @@ readchunk: /** * Seek method based on the one described in the Appendix C of QTFileFormat.pdf */ -static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) +static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags) { MOVContext* mov = (MOVContext *) s->priv_data; MOVStreamContext* sc; int32_t i, a, b, m; - int64_t sample_time; int64_t start_time; int32_t seek_sample, sample; int32_t duration; @@ -2100,10 +2070,6 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp #ifdef DEBUG av_log(s, AV_LOG_DEBUG, "Searching for time %li in stream #%i (time_scale=%i)\n", (long)timestamp, mov_idx, sc->time_scale); #endif - // convert timestamp from time_base unit to timescale unit - sample_time = av_rescale( timestamp, - (int64_t)sc->time_scale * s->streams[stream_index]->time_base.num, - (int64_t)s->streams[stream_index]->time_base.den); start_time = 0; // FIXME use elst atom sample = 1; // sample are 0 based in table #ifdef DEBUG