changeset 462:b69898ffc92a libavformat

move time_base (pts_num/pts_den) from AVFormatContext -> AVStream
author michael
date Fri, 21 May 2004 20:43:21 +0000
parents 63540e5504f7
children 696f41bc8784
files 4xm.c asf-enc.c asf.c audio.c avformat.h avidec.c dv.c flic.c flvdec.c flvenc.c grab.c idcin.c idroq.c img.c ipmovie.c matroska.c mpegts.c nut.c ogg.c psxstr.c segafilm.c sierravmd.c swf.c utils.c wc3movie.c westwood.c
diffstat 26 files changed, 100 insertions(+), 124 deletions(-) [+]
line wrap: on
line diff
--- a/4xm.c	Thu May 20 16:00:22 2004 +0000
+++ b/4xm.c	Fri May 21 20:43:21 2004 +0000
@@ -164,6 +164,7 @@
             st = av_new_stream(s, 0);
             if (!st)
                 return AVERROR_NOMEM;
+            av_set_pts_info(st, 33, 1, 90000);
 
             fourxm->video_stream_index = st->index;
 
@@ -202,6 +203,9 @@
             if (!st)
                 return AVERROR_NOMEM;
 
+            /* set the pts reference (1 pts = 1/90000) */
+            av_set_pts_info(st, 33, 1, 90000);
+
             fourxm->tracks[current_track].stream_index = st->index;
 
             st->codec.codec_type = CODEC_TYPE_AUDIO;
@@ -232,10 +236,6 @@
     fourxm->video_pts = -fourxm->video_pts_inc;  /* first frame will push to 0 */
     fourxm->audio_pts = 0;
 
-    /* set the pts reference (1 pts = 1/90000) */
-    s->pts_num = 1;
-    s->pts_den = 90000;
-
     return 0;
 }
 
--- a/asf-enc.c	Thu May 20 16:00:22 2004 +0000
+++ b/asf-enc.c	Fri May 21 20:43:21 2004 +0000
@@ -285,6 +285,8 @@
     for(n=0;n<s->nb_streams;n++) {
         enc = &s->streams[n]->codec;
 
+        av_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */
+
         bit_rate += enc->bit_rate;
     }
 
@@ -469,8 +471,6 @@
 {
     ASFContext *asf = s->priv_data;
 
-    av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
-
     asf->packet_size = PACKET_SIZE;
     asf->nb_packets = 0;
 
--- a/asf.c	Thu May 20 16:00:22 2004 +0000
+++ b/asf.c	Fri May 21 20:43:21 2004 +0000
@@ -148,8 +148,6 @@
     int size, i;
     int64_t gsize;
 
-    av_set_pts_info(s, 32, 1, 1000); /* 32 bit pts in ms */
-
     get_guid(pb, &g);
     if (memcmp(&g, &asf_header, sizeof(GUID)))
         goto fail;
@@ -193,6 +191,7 @@
             st = av_new_stream(s, 0);
             if (!st)
                 goto fail;
+            av_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */
             asf_st = av_mallocz(sizeof(ASFStream));
             if (!asf_st)
                 goto fail;
--- a/audio.c	Thu May 20 16:00:22 2004 +0000
+++ b/audio.c	Fri May 21 20:43:21 2004 +0000
@@ -230,7 +230,7 @@
     st->codec.sample_rate = s->sample_rate;
     st->codec.channels = s->channels;
 
-    av_set_pts_info(s1, 48, 1, 1000000);  /* 48 bits pts in us */
+    av_set_pts_info(st, 48, 1, 1000000);  /* 48 bits pts in us */
     return 0;
 }
 
--- a/avformat.h	Thu May 20 16:00:22 2004 +0000
+++ b/avformat.h	Fri May 21 20:43:21 2004 +0000
@@ -214,6 +214,8 @@
     int codec_info_nb_frames;
     /* encoding: PTS generation when outputing stream */
     AVFrac pts;
+    AVRational time_base;
+    int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
     /* ffmpeg.c private use */
     int stream_copy; /* if TRUE, just copy stream */
     /* quality, as it has been removed from AVCodecContext and put in AVVideoFrame
@@ -226,6 +228,14 @@
        seconds. */
     int64_t duration;
 
+    /* the following are used for pts/dts unit conversion */
+    int64_t last_pkt_stream_pts;
+    int64_t last_pkt_stream_dts;
+    int64_t last_pkt_pts;
+    int64_t last_pkt_dts;
+    int last_pkt_pts_frac;
+    int last_pkt_dts_frac;
+    
     /* av_read_frame() support */
     int need_parsing;
     struct AVCodecParserContext *parser;
@@ -268,8 +278,6 @@
 
     int ctx_flags; /* format specific flags, see AVFMTCTX_xx */
     /* private data for pts handling (do not modify directly) */
-    int pts_wrap_bits; /* number of bits in pts (used for wrapping control) */
-    int pts_num, pts_den; /* value to convert to seconds */
     /* This buffer is only needed when packets were already buffered but
        not decoded, for example to get the codec parameters in mpeg
        streams */
@@ -296,14 +304,6 @@
     int cur_len;
     AVPacket cur_pkt;
 
-    /* the following are used for pts/dts unit conversion */
-    int64_t last_pkt_stream_pts;
-    int64_t last_pkt_stream_dts;
-    int64_t last_pkt_pts;
-    int64_t last_pkt_dts;
-    int last_pkt_pts_frac;
-    int last_pkt_dts_frac;
-
     /* av_seek_frame() support */
     int64_t data_offset; /* offset of the first packet */
     int index_built;
@@ -553,7 +553,7 @@
 int av_read_pause(AVFormatContext *s);
 void av_close_input_file(AVFormatContext *s);
 AVStream *av_new_stream(AVFormatContext *s, int id);
-void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
+void av_set_pts_info(AVStream *s, int pts_wrap_bits,
                      int pts_num, int pts_den);
 
 int av_find_default_stream_index(AVFormatContext *s);
--- a/avidec.c	Thu May 20 16:00:22 2004 +0000
+++ b/avidec.c	Fri May 21 20:43:21 2004 +0000
@@ -93,8 +93,6 @@
     AVIStream *ast;
     int xan_video = 0;  /* hack to support Xan A/V */
 
-    av_set_pts_info(s, 64, 1, AV_TIME_BASE);
-
     if (get_riff(avi, pb) < 0)
         return -1;
 
@@ -139,6 +137,8 @@
                 st = av_new_stream(s, i);
                 if (!st)
                     goto fail;
+                av_set_pts_info(st, 64, 1, AV_TIME_BASE);
+
                 ast = av_mallocz(sizeof(AVIStream));
                 if (!ast)
                     goto fail;
--- a/dv.c	Thu May 20 16:00:22 2004 +0000
+++ b/dv.c	Fri May 21 20:43:21 2004 +0000
@@ -550,6 +550,7 @@
     if (c->ach == 2 && !c->ast[1]) {
         c->ast[1] = av_new_stream(c->fctx, 0);
 	if (c->ast[1]) {
+            av_set_pts_info(c->ast[1], 64, 1, 30000);
 	    c->ast[1]->codec.codec_type = CODEC_TYPE_AUDIO;
 	    c->ast[1]->codec.codec_id = CODEC_ID_PCM_S16LE;
 	} else
@@ -721,6 +722,9 @@
     c->ast[0] = av_new_stream(s, 0);
     if (!c->vst || !c->ast[0])
         goto fail;
+    av_set_pts_info(c->vst, 64, 1, 30000);
+    av_set_pts_info(c->ast[0], 64, 1, 30000);
+
     c->fctx = s;
     c->ast[1] = NULL;
     c->ach = 0;
@@ -738,8 +742,6 @@
    
     s->ctx_flags |= AVFMTCTX_NOHEADER; 
     
-    av_set_pts_info(s, 64, 1, 30000);
-    
     return c;
     
 fail:
--- a/flic.c	Thu May 20 16:00:22 2004 +0000
+++ b/flic.c	Fri May 21 20:43:21 2004 +0000
@@ -100,9 +100,7 @@
     st->codec.extradata = av_malloc(FLIC_HEADER_SIZE);
     memcpy(st->codec.extradata, header, FLIC_HEADER_SIZE);
 
-    /* set the pts reference (1 pts = 1/90000) */
-    s->pts_num = 1;
-    s->pts_den = 90000;
+    av_set_pts_info(st, 33, 1, 90000);
 
     /* Time to figure out the framerate: If there is a FLIC chunk magic
      * number at offset 0x10, assume this is from the Bullfrog game,
--- a/flvdec.c	Thu May 20 16:00:22 2004 +0000
+++ b/flvdec.c	Fri May 21 20:43:21 2004 +0000
@@ -48,8 +48,6 @@
     
     s->ctx_flags |= AVFMTCTX_NOHEADER; //ok we have a header but theres no fps, codec type, sample_rate, ...
 
-    av_set_pts_info(s, 24, 1, 1000); /* 24 bit pts in ms */
-
     url_fskip(&s->pb, 4);
     flags = get_byte(&s->pb);
 
@@ -103,6 +101,8 @@
         st = av_new_stream(s, is_audio);
         if (!st)
             return AVERROR_NOMEM;
+
+        av_set_pts_info(st, 24, 1, 1000); /* 24 bit pts in ms */
         st->codec.frame_rate_base= 0;
     }
     break;
--- a/flvenc.c	Thu May 20 16:00:22 2004 +0000
+++ b/flvenc.c	Fri May 21 20:43:21 2004 +0000
@@ -134,8 +134,6 @@
     FLVContext *flv = s->priv_data;
     int i;
 
-    av_set_pts_info(s, 24, 1, 1000); /* 24 bit pts in ms */
-
     flv->hasAudio = 0;
     flv->hasVideo = 0;
 
@@ -151,6 +149,7 @@
     
     for(i=0; i<s->nb_streams; i++){
         AVCodecContext *enc = &s->streams[i]->codec;
+        av_set_pts_info(s->streams[i], 24, 1, 1000); /* 24 bit pts in ms */
         if(enc->codec_tag == 5){
             put_byte(pb,8); // message type
             put_be24(pb,0); // include flags
--- a/grab.c	Thu May 20 16:00:22 2004 +0000
+++ b/grab.c	Fri May 21 20:43:21 2004 +0000
@@ -79,6 +79,7 @@
     st = av_new_stream(s1, 0);
     if (!st)
         return -ENOMEM;
+    av_set_pts_info(st, 48, 1, 1000000); /* 48 bits pts in us */
 
     s->width = width;
     s->height = height;
@@ -263,8 +264,6 @@
     st->codec.height = height;
     st->codec.frame_rate      = frame_rate;
     st->codec.frame_rate_base = frame_rate_base;
-    
-    av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */
 
     return 0;
  fail:
--- a/idcin.c	Thu May 20 16:00:22 2004 +0000
+++ b/idcin.c	Fri May 21 20:43:21 2004 +0000
@@ -154,6 +154,7 @@
     st = av_new_stream(s, 0);
     if (!st)
         return AVERROR_NOMEM;
+    av_set_pts_info(st, 33, 1, 90000);
     idcin->video_stream_index = st->index;
     st->codec.codec_type = CODEC_TYPE_VIDEO;
     st->codec.codec_id = CODEC_ID_IDCIN;
@@ -176,6 +177,7 @@
         st = av_new_stream(s, 0);
         if (!st)
             return AVERROR_NOMEM;
+        av_set_pts_info(st, 33, 1, 90000);
         idcin->audio_stream_index = st->index;
         st->codec.codec_type = CODEC_TYPE_AUDIO;
         st->codec.codec_tag = 1;
@@ -205,10 +207,6 @@
     idcin->next_chunk_is_video = 1;
     idcin->pts = 0;
 
-    /* set the pts reference (1 pts = 1/90000) */
-    s->pts_num = 1;
-    s->pts_den = 90000;
-
     return 0;
 }
 
--- a/idroq.c	Thu May 20 16:00:22 2004 +0000
+++ b/idroq.c	Fri May 21 20:43:21 2004 +0000
@@ -84,10 +84,6 @@
     roq->framerate = LE_16(&preamble[6]);
     roq->frame_pts_inc = 90000 / roq->framerate;
 
-    /* set the pts reference (1 pts = 1/90000) */
-    s->pts_num = 1;
-    s->pts_den = 90000;
-
     /* init private context parameters */
     roq->width = roq->height = roq->audio_channels = roq->video_pts = 
     roq->audio_frame_count = 0;
@@ -146,6 +142,8 @@
     st = av_new_stream(s, 0);
     if (!st)
         return AVERROR_NOMEM;
+    /* set the pts reference (1 pts = 1/90000) */
+    av_set_pts_info(st, 33, 1, 90000);
     roq->video_stream_index = st->index;
     st->codec.codec_type = CODEC_TYPE_VIDEO;
     st->codec.codec_id = CODEC_ID_ROQ;
@@ -157,6 +155,7 @@
         st = av_new_stream(s, 0);
         if (!st)
             return AVERROR_NOMEM;
+        av_set_pts_info(st, 33, 1, 90000);
         roq->audio_stream_index = st->index;
         st->codec.codec_type = CODEC_TYPE_AUDIO;
         st->codec.codec_id = CODEC_ID_ROQ_DPCM;
--- a/img.c	Thu May 20 16:00:22 2004 +0000
+++ b/img.c	Fri May 21 20:43:21 2004 +0000
@@ -236,7 +236,7 @@
     } else {
         /* XXX: computing this pts is not necessary as it is done in
            the generic code too */
-        pkt->pts = av_rescale((int64_t)s->img_count * s1->streams[0]->codec.frame_rate_base, s1->pts_den, s1->streams[0]->codec.frame_rate) / s1->pts_num;
+        pkt->pts = av_rescale((int64_t)s->img_count * s1->streams[0]->codec.frame_rate_base, s1->streams[0]->time_base.den, s1->streams[0]->codec.frame_rate) / s1->streams[0]->time_base.num;
         s->img_count++;
         s->img_number++;
         return 0;
--- a/ipmovie.c	Thu May 20 16:00:22 2004 +0000
+++ b/ipmovie.c	Fri May 21 20:43:21 2004 +0000
@@ -552,14 +552,11 @@
     else if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_AUDIO)
         return AVERROR_INVALIDDATA;
 
-    /* set the pts reference (1 pts = 1/90000) */
-    s->pts_num = 1;
-    s->pts_den = 90000;
-
     /* initialize the stream decoders */
     st = av_new_stream(s, 0);
     if (!st)
         return AVERROR_NOMEM;
+    av_set_pts_info(st, 33, 1, 90000);
     ipmovie->video_stream_index = st->index;
     st->codec.codec_type = CODEC_TYPE_VIDEO;
     st->codec.codec_id = CODEC_ID_INTERPLAY_VIDEO;
@@ -574,6 +571,7 @@
         st = av_new_stream(s, 0);
         if (!st)
             return AVERROR_NOMEM;
+        av_set_pts_info(st, 33, 1, 90000);
         ipmovie->audio_stream_index = st->index;
         st->codec.codec_type = CODEC_TYPE_AUDIO;
         st->codec.codec_id = ipmovie->audio_type;
--- a/matroska.c	Thu May 20 16:00:22 2004 +0000
+++ b/matroska.c	Fri May 21 20:43:21 2004 +0000
@@ -2152,8 +2152,6 @@
         MatroskaTrack *track;
         AVStream *st;
 
-        av_set_pts_info(s, 24, 1, 1000); /* 24 bit pts in ms */
-
         for (i = 0; i < matroska->num_tracks; i++) {
             track = matroska->tracks[i];
 
@@ -2257,6 +2255,7 @@
             st = av_new_stream(s, track->stream_index);
             if (st == NULL)
                 return AVERROR_NOMEM;
+            av_set_pts_info(st, 24, 1, 1000); /* 24 bit pts in ms */
 
             st->codec.codec_id = codec_id;
 
--- a/mpegts.c	Thu May 20 16:00:22 2004 +0000
+++ b/mpegts.c	Fri May 21 20:43:21 2004 +0000
@@ -768,6 +768,7 @@
                         }
                         st = av_new_stream(pes->stream, pes->pid);
                         if (st) {
+                            av_set_pts_info(st, 60, 1, 27000000);
                             st->priv_data = pes;
                             st->codec.codec_type = codec_type;
                             st->codec.codec_id = codec_id;
@@ -1165,14 +1166,12 @@
         uint8_t packet[TS_PACKET_SIZE];
         
         /* only read packets */
-
-        s->pts_num = 1;
-        s->pts_den = 27000000;
         
     do_pcr:
         st = av_new_stream(s, 0);
         if (!st)
             goto fail;
+        av_set_pts_info(st, 60, 1, 27000000);
         st->codec.codec_type = CODEC_TYPE_DATA;
         st->codec.codec_id = CODEC_ID_MPEG2TS;
         
--- a/nut.c	Thu May 20 16:00:22 2004 +0000
+++ b/nut.c	Fri May 21 20:43:21 2004 +0000
@@ -511,8 +511,6 @@
     nut->stream =	
 	av_mallocz(sizeof(StreamContext)*s->nb_streams);
     
-    av_set_pts_info(s, 60, 1, AV_TIME_BASE);
-    
     /* main header */
     put_be64(bc, MAIN_STARTCODE);
     put_packetheader(nut, bc, 120+5*256, 1);
@@ -572,6 +570,7 @@
 	int nom, denom, gcd;
 
 	codec = &s->streams[i]->codec;
+        av_set_pts_info(s->streams[i], 60, 1, AV_TIME_BASE);
 	
 	put_be64(bc, STREAM_STARTCODE);
 	put_packetheader(nut, bc, 120 + codec->extradata_size, 1);
@@ -945,6 +944,8 @@
     st = av_new_stream(s, stream_id);
     if (!st)
         return AVERROR_NOMEM;
+    av_set_pts_info(st, 60, 1, AV_TIME_BASE);
+
     class = get_v(bc);
     tmp = get_vb(bc);
     st->codec.codec_tag= tmp;
@@ -1069,8 +1070,6 @@
 
     nut->avf= s;
     
-    av_set_pts_info(s, 60, 1, AV_TIME_BASE);
-
     /* main header */
     pos=0;
     for(;;){
--- a/ogg.c	Thu May 20 16:00:22 2004 +0000
+++ b/ogg.c	Fri May 21 20:43:21 2004 +0000
@@ -36,14 +36,14 @@
     ogg_packet *op= &context->op;    
     int n, i;
 
-    av_set_pts_info(avfcontext, 60, 1, AV_TIME_BASE);
-
     ogg_stream_init(&context->os, 31415);
     
     for(n = 0 ; n < avfcontext->nb_streams ; n++) {
         AVCodecContext *codec = &avfcontext->streams[n]->codec;
         uint8_t *p= codec->extradata;
         
+        av_set_pts_info(avfcontext->streams[n], 60, 1, AV_TIME_BASE);
+
         for(i=0; i < codec->extradata_size; i+= op->bytes){
             op->bytes = p[i++]<<8;
             op->bytes+= p[i++];
@@ -172,7 +172,6 @@
     int i;
      
     avfcontext->ctx_flags |= AVFMTCTX_NOHEADER;
-    av_set_pts_info(avfcontext, 60, 1, AV_TIME_BASE);
      
     ogg_sync_init(&context->oy) ;
     buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ;
@@ -190,6 +189,7 @@
     ast = av_new_stream(avfcontext, 0) ;
     if(!ast)
 	return AVERROR_NOMEM ;
+    av_set_pts_info(ast, 60, 1, AV_TIME_BASE);
 
     codec= &ast->codec;
     codec->codec_type = CODEC_TYPE_AUDIO;
--- a/psxstr.c	Thu May 20 16:00:22 2004 +0000
+++ b/psxstr.c	Fri May 21 20:43:21 2004 +0000
@@ -135,9 +135,6 @@
     str->video_channel = -1;
     str->video_chunk = NULL;
 
-    /* set the pts reference (1 pts = 1/90000) */
-    s->pts_num = 1;
-    s->pts_den = 90000;
 
     /* skip over any RIFF header */
     if (get_buffer(pb, sector, RIFF_HEADER_SIZE) != RIFF_HEADER_SIZE)
@@ -178,6 +175,8 @@
                 st = av_new_stream(s, 0);
                 if (!st)
                     return AVERROR_NOMEM;
+                /* set the pts reference (1 pts = 1/90000) */
+                av_set_pts_info(st, 33, 1, 90000);
 
                 str->channels[channel].video_stream_index = st->index;
 
@@ -206,6 +205,7 @@
                 st = av_new_stream(s, 0);
                 if (!st)
                     return AVERROR_NOMEM;
+                av_set_pts_info(st, 33, 1, 90000);
 
                 str->channels[channel].audio_stream_index = st->index;
 
--- a/segafilm.c	Thu May 20 16:00:22 2004 +0000
+++ b/segafilm.c	Fri May 21 20:43:21 2004 +0000
@@ -173,6 +173,9 @@
     film->sample_count = BE_32(&scratch[12]);
     film->sample_table = av_malloc(film->sample_count * sizeof(film_sample_t));
     
+    for(i=0; i<s->nb_streams; i++)
+        av_set_pts_info(s->streams[i], 33, 1, film->base_clock);
+    
     audio_frame_counter = 0;
     for (i = 0; i < film->sample_count; i++) {
         /* load the next sample record and transfer it to an internal struct */
@@ -200,10 +203,6 @@
 
     film->current_sample = 0;
 
-    /* set the pts reference to match the tick rate of the file */
-    s->pts_num = 1;
-    s->pts_den = film->base_clock;
-
     return 0;
 }
 
--- a/sierravmd.c	Thu May 20 16:00:22 2004 +0000
+++ b/sierravmd.c	Fri May 21 20:43:21 2004 +0000
@@ -129,6 +129,7 @@
     st = av_new_stream(s, 0);
     if (!st)
         return AVERROR_NOMEM;
+    av_set_pts_info(st, 33, 1, 90000);
     vmd->video_stream_index = st->index;
     st->codec.codec_type = CODEC_TYPE_VIDEO;
     st->codec.codec_id = CODEC_ID_VMDVIDEO;
@@ -145,6 +146,7 @@
         st = av_new_stream(s, 0);
         if (!st)
             return AVERROR_NOMEM;
+        av_set_pts_info(st, 33, 1, 90000);
         vmd->audio_stream_index = st->index;
         st->codec.codec_type = CODEC_TYPE_AUDIO;
         st->codec.codec_id = CODEC_ID_VMDAUDIO;
@@ -243,10 +245,6 @@
 
     av_free(raw_frame_table);
 
-    /* set the pts reference at 1 pts = 1/90000 sec */
-    s->pts_num = 1;
-    s->pts_den = 90000;
-
     vmd->current_frame = 0;
 
     return 0;
--- a/swf.c	Thu May 20 16:00:22 2004 +0000
+++ b/swf.c	Fri May 21 20:43:21 2004 +0000
@@ -805,8 +805,6 @@
     frame_rate = get_le16(pb);
     get_le16(pb); /* frame count */
     
-    av_set_pts_info(s, 24, 1, 1000); /* 24 bit pts in ms */
-    
     /* The Flash Player converts 8.8 frame rates 
        to milliseconds internally. Do the same to get 
        a correct framerate */
@@ -837,6 +835,8 @@
             /* Check for FLV1 */
             if ( get_byte(pb) == SWF_VIDEO_CODEC_FLV1 ) {
                 vst = av_new_stream(s, 0);
+                av_set_pts_info(vst, 24, 1, 1000); /* 24 bit pts in ms */
+    
                 vst->codec.codec_type = CODEC_TYPE_VIDEO;
                 vst->codec.codec_id = CODEC_ID_FLV1;
                 if ( swf->samples_per_frame ) {
@@ -857,6 +857,7 @@
                     get_le16(pb);
                 }
                 ast = av_new_stream(s, 1);
+                av_set_pts_info(ast, 24, 1, 1000); /* 24 bit pts in ms */
                 if (!ast)
                     return -ENOMEM;
 
--- a/utils.c	Thu May 20 16:00:22 2004 +0000
+++ b/utils.c	Fri May 21 20:43:21 2004 +0000
@@ -355,13 +355,6 @@
         ic->priv_data = NULL;
     }
 
-    /* default pts settings is MPEG like */
-    av_set_pts_info(ic, 33, 1, 90000);
-    ic->last_pkt_pts = AV_NOPTS_VALUE;
-    ic->last_pkt_dts = AV_NOPTS_VALUE;
-    ic->last_pkt_stream_pts = AV_NOPTS_VALUE;
-    ic->last_pkt_stream_dts = AV_NOPTS_VALUE;
-    
     err = ic->iformat->read_header(ic, ap);
     if (err < 0)
         goto fail;
@@ -499,7 +492,7 @@
    wrapping is handled by considering the next PTS/DTS as a delta to
    the previous value. We handle the delta as a fraction to avoid any
    rounding errors. */
-static inline int64_t convert_timestamp_units(AVFormatContext *s,
+static inline int64_t convert_timestamp_units(AVStream *s,
                                         int64_t *plast_pkt_pts,
                                         int *plast_pkt_pts_frac,
                                         int64_t *plast_pkt_stream_pts,
@@ -515,17 +508,18 @@
             shift = 64 - s->pts_wrap_bits;
             delta_pts = ((stream_pts - *plast_pkt_stream_pts) << shift) >> shift;
             /* XXX: overflow possible but very unlikely as it is a delta */
-            delta_pts = delta_pts * AV_TIME_BASE * s->pts_num;
-            pts = *plast_pkt_pts + (delta_pts / s->pts_den);
-            pts_frac = *plast_pkt_pts_frac + (delta_pts % s->pts_den);
-            if (pts_frac >= s->pts_den) {
-                pts_frac -= s->pts_den;
+            delta_pts = delta_pts * AV_TIME_BASE * s->time_base.num;
+            pts = *plast_pkt_pts + (delta_pts / s->time_base.den);
+            pts_frac = *plast_pkt_pts_frac + (delta_pts % s->time_base.den);
+            if (pts_frac >= s->time_base.den) {
+                pts_frac -= s->time_base.den;
                 pts++;
             }
         } else {
             /* no previous pts, so no wrapping possible */
-            pts = (int64_t)(((double)stream_pts * AV_TIME_BASE * s->pts_num) / 
-                            (double)s->pts_den);
+//            pts = av_rescale(stream_pts, (int64_t)AV_TIME_BASE * s->time_base.num, s->time_base.den);
+            pts = (int64_t)(((double)stream_pts * AV_TIME_BASE * s->time_base.num) / 
+                            (double)s->time_base.den);
             pts_frac = 0;
         }
         *plast_pkt_stream_pts = stream_pts;
@@ -752,15 +746,17 @@
                 /* no more packets: really terminates parsing */
                 return ret;
             }
+            
+            st = s->streams[s->cur_pkt.stream_index];
 
             /* convert the packet time stamp units and handle wrapping */
-            s->cur_pkt.pts = convert_timestamp_units(s, 
-                                               &s->last_pkt_pts, &s->last_pkt_pts_frac,
-                                               &s->last_pkt_stream_pts,
+            s->cur_pkt.pts = convert_timestamp_units(st, 
+                                               &st->last_pkt_pts, &st->last_pkt_pts_frac,
+                                               &st->last_pkt_stream_pts,
                                                s->cur_pkt.pts);
-            s->cur_pkt.dts = convert_timestamp_units(s, 
-                                               &s->last_pkt_dts,  &s->last_pkt_dts_frac,
-                                               &s->last_pkt_stream_dts,
+            s->cur_pkt.dts = convert_timestamp_units(st, 
+                                               &st->last_pkt_dts,  &st->last_pkt_dts_frac,
+                                               &st->last_pkt_stream_dts,
                                                s->cur_pkt.dts);
 #if 0
             if (s->cur_pkt.stream_index == 0) {
@@ -772,14 +768,10 @@
                            (double)s->cur_pkt.dts / AV_TIME_BASE);
             }
 #endif
-            
+
             /* duration field */
-            if (s->cur_pkt.duration != 0) {
-                s->cur_pkt.duration = ((int64_t)s->cur_pkt.duration * AV_TIME_BASE * s->pts_num) / 
-                    s->pts_den;
-            }
+            s->cur_pkt.duration = av_rescale(s->cur_pkt.duration, AV_TIME_BASE * (int64_t)st->time_base.num, st->time_base.den);
 
-            st = s->streams[s->cur_pkt.stream_index];
             s->cur_st = st;
             s->cur_ptr = s->cur_pkt.data;
             s->cur_len = s->cur_pkt.size;
@@ -1355,7 +1347,7 @@
         st = ic->streams[pkt->stream_index];
         if (pkt->pts != AV_NOPTS_VALUE) {
             if (st->start_time == AV_NOPTS_VALUE)
-                st->start_time = (int64_t)((double)pkt->pts * ic->pts_num * (double)AV_TIME_BASE / ic->pts_den);
+                st->start_time = av_rescale(pkt->pts, st->time_base.num * (int64_t)AV_TIME_BASE, st->time_base.den);
         }
         av_free_packet(pkt);
     }
@@ -1398,7 +1390,7 @@
         read_size += pkt->size;
         st = ic->streams[pkt->stream_index];
         if (pkt->pts != AV_NOPTS_VALUE) {
-            end_time = (int64_t)((double)pkt->pts * ic->pts_num * (double)AV_TIME_BASE / ic->pts_den);
+            end_time = av_rescale(pkt->pts, st->time_base.num * (int64_t)AV_TIME_BASE, st->time_base.den);
             duration = end_time - st->start_time;
             if (duration > 0) {
                 if (st->duration == AV_NOPTS_VALUE ||
@@ -1776,6 +1768,14 @@
     st->id = id;
     st->start_time = AV_NOPTS_VALUE;
     st->duration = AV_NOPTS_VALUE;
+
+    /* default pts settings is MPEG like */
+    av_set_pts_info(st, 33, 1, 90000);
+    st->last_pkt_pts = AV_NOPTS_VALUE;
+    st->last_pkt_dts = AV_NOPTS_VALUE;
+    st->last_pkt_stream_pts = AV_NOPTS_VALUE;
+    st->last_pkt_stream_dts = AV_NOPTS_VALUE;
+
     s->streams[s->nb_streams++] = st;
     return st;
 }
@@ -1814,8 +1814,6 @@
     int ret, i;
     AVStream *st;
 
-    /* default pts settings is MPEG like */
-    av_set_pts_info(s, 33, 1, 90000);
     ret = s->oformat->write_header(s);
     if (ret < 0)
         return ret;
@@ -1827,11 +1825,11 @@
         switch (st->codec.codec_type) {
         case CODEC_TYPE_AUDIO:
             av_frac_init(&st->pts, 0, 0, 
-                         (int64_t)s->pts_num * st->codec.sample_rate);
+                         (int64_t)st->time_base.num * st->codec.sample_rate);
             break;
         case CODEC_TYPE_VIDEO:
             av_frac_init(&st->pts, 0, 0, 
-                         (int64_t)s->pts_num * st->codec.frame_rate);
+                         (int64_t)st->time_base.num * st->codec.frame_rate);
             break;
         default:
             break;
@@ -1858,7 +1856,7 @@
     int ret, frame_size;
 
     st = s->streams[stream_index];
-    pts_mask = (1LL << s->pts_wrap_bits) - 1;
+    pts_mask = (1LL << st->pts_wrap_bits) - 1;
 
     /* HACK/FIXME we skip all zero size audio packets so a encoder can pass pts by outputing zero size packets */
     if(st->codec.codec_type==CODEC_TYPE_AUDIO && size==0)
@@ -1878,13 +1876,11 @@
         /* HACK/FIXME, we skip the initial 0-size packets as they are most likely equal to the encoder delay,
            but it would be better if we had the real timestamps from the encoder */
         if (frame_size >= 0 && (size || st->pts.num!=st->pts.den>>1 || st->pts.val)) {
-            av_frac_add(&st->pts, 
-                        (int64_t)s->pts_den * frame_size);
+            av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size);
         }
         break;
     case CODEC_TYPE_VIDEO:
-        av_frac_add(&st->pts, 
-                    (int64_t)s->pts_den * st->codec.frame_rate_base);
+        av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec.frame_rate_base);
         break;
     default:
         break;
@@ -2375,12 +2371,12 @@
  * @param pts_num numerator to convert to seconds (MPEG: 1) 
  * @param pts_den denominator to convert to seconds (MPEG: 90000)
  */
-void av_set_pts_info(AVFormatContext *s, int pts_wrap_bits,
+void av_set_pts_info(AVStream *s, int pts_wrap_bits,
                      int pts_num, int pts_den)
 {
     s->pts_wrap_bits = pts_wrap_bits;
-    s->pts_num = pts_num;
-    s->pts_den = pts_den;
+    s->time_base.num = pts_num;
+    s->time_base.den = pts_den;
 }
 
 /* fraction handling */
--- a/wc3movie.c	Thu May 20 16:00:22 2004 +0000
+++ b/wc3movie.c	Fri May 21 20:43:21 2004 +0000
@@ -233,6 +233,7 @@
     st = av_new_stream(s, 0);
     if (!st)
         return AVERROR_NOMEM;
+    av_set_pts_info(st, 33, 1, 90000);
     wc3->video_stream_index = st->index;
     st->codec.codec_type = CODEC_TYPE_VIDEO;
     st->codec.codec_id = CODEC_ID_XAN_WC3;
@@ -246,6 +247,7 @@
     st = av_new_stream(s, 0);
     if (!st)
         return AVERROR_NOMEM;
+    av_set_pts_info(st, 33, 1, 90000);
     wc3->audio_stream_index = st->index;
     st->codec.codec_type = CODEC_TYPE_AUDIO;
     st->codec.codec_id = CODEC_ID_PCM_S16LE;
@@ -257,10 +259,6 @@
         st->codec.bits_per_sample;
     st->codec.block_align = WC3_AUDIO_BITS * WC3_AUDIO_CHANNELS;
 
-    /* set the pts reference (1 pts = 1/90000) */
-    s->pts_num = 1;
-    s->pts_den = 90000;
-
     return 0;
 }
 
--- a/westwood.c	Thu May 20 16:00:22 2004 +0000
+++ b/westwood.c	Fri May 21 20:43:21 2004 +0000
@@ -131,14 +131,11 @@
     /* flag 1 indicates 16 bit audio */
     wsaud->audio_bits = (((header[10] & 0x2) >> 1) + 1) * 8;
 
-    /* set the pts reference the same as the sample rate */
-    s->pts_num = 1;
-    s->pts_den = wsaud->audio_samplerate;
-
     /* initialize the audio decoder stream */
     st = av_new_stream(s, 0);
     if (!st)
         return AVERROR_NOMEM;
+    av_set_pts_info(st, 33, 1, wsaud->audio_samplerate);
     st->codec.codec_type = CODEC_TYPE_AUDIO;
     st->codec.codec_id = wsaud->audio_type;
     st->codec.codec_tag = 0;  /* no tag */
@@ -222,14 +219,11 @@
     unsigned int chunk_tag;
     unsigned int chunk_size;
 
-    /* set the pts reference (1 pts = 1/90000) */
-    s->pts_num = 1;
-    s->pts_den = 90000;
-
     /* initialize the video decoder stream */
     st = av_new_stream(s, 0);
     if (!st)
         return AVERROR_NOMEM;
+    av_set_pts_info(st, 33, 1, 90000);
     wsvqa->video_stream_index = st->index;
     st->codec.codec_type = CODEC_TYPE_VIDEO;
     st->codec.codec_id = CODEC_ID_WS_VQA;
@@ -255,6 +249,7 @@
         st = av_new_stream(s, 0);
         if (!st)
             return AVERROR_NOMEM;
+        av_set_pts_info(st, 33, 1, 90000);
         st->codec.codec_type = CODEC_TYPE_AUDIO;
         st->codec.codec_id = CODEC_ID_ADPCM_IMA_WS;
         st->codec.codec_tag = 0;  /* no tag */