[Ffmpeg-cvslog] CVS: ffmpeg ffmpeg.c, 1.326, 1.327 ffplay.c, 1.41, 1.42 ffserver.c, 1.90, 1.91 output_example.c, 1.12, 1.13

Michael Niedermayer CVS michael
Sat Apr 30 23:44:28 CEST 2005


Update of /cvsroot/ffmpeg/ffmpeg
In directory mail:/var2/tmp/cvs-serv21767

Modified Files:
	ffmpeg.c ffplay.c ffserver.c output_example.c 
Log Message:
switch to native time bases


Index: ffmpeg.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/ffmpeg.c,v
retrieving revision 1.326
retrieving revision 1.327
diff -u -d -r1.326 -r1.327
--- ffmpeg.c	25 Apr 2005 18:29:04 -0000	1.326
+++ ffmpeg.c	30 Apr 2005 21:43:55 -0000	1.327
@@ -556,7 +556,7 @@
             pkt.data= audio_out;
             pkt.size= ret;
             if(enc->coded_frame)
-                pkt.pts= enc->coded_frame->pts;
+                pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
             pkt.flags |= PKT_FLAG_KEY;
             av_interleaved_write_frame(s, &pkt);
             
@@ -587,7 +587,7 @@
         pkt.data= audio_out;
         pkt.size= ret;
         if(enc->coded_frame)
-            pkt.pts= enc->coded_frame->pts;
+            pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
         pkt.flags |= PKT_FLAG_KEY;
         av_interleaved_write_frame(s, &pkt);
     }
@@ -708,7 +708,7 @@
 
     if(video_sync_method){
         double vdelta;
-        vdelta = ost->sync_ipts * enc->frame_rate / enc->frame_rate_base - ost->sync_opts;
+        vdelta = ost->sync_ipts / av_q2d(enc->time_base) - ost->sync_opts;
         //FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c
         if (vdelta < -1.1)
             nb_frames = 0;
@@ -725,7 +725,7 @@
                 fprintf(stderr, "*** %d dup!\n", nb_frames-1);
         }
     }else
-        ost->sync_opts= lrintf(ost->sync_ipts * enc->frame_rate / enc->frame_rate_base);
+        ost->sync_opts= lrintf(ost->sync_ipts / av_q2d(enc->time_base));
 
     nb_frames= FFMIN(nb_frames, max_frames[CODEC_TYPE_VIDEO] - ost->frame_number);
     if (nb_frames <= 0) 
@@ -875,7 +875,7 @@
             pkt.data= (uint8_t *)final_picture;
             pkt.size=  sizeof(AVPicture);
             if(dec->coded_frame)
-                pkt.pts= dec->coded_frame->pts;
+                pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
             if(dec->coded_frame && dec->coded_frame->key_frame)
                 pkt.flags |= PKT_FLAG_KEY;
 
@@ -904,7 +904,8 @@
             if(!me_threshold)
                 big_picture.pict_type = 0;
 //            big_picture.pts = AV_NOPTS_VALUE;
-            big_picture.pts= av_rescale(ost->sync_opts, AV_TIME_BASE*(int64_t)enc->frame_rate_base, enc->frame_rate);
+            big_picture.pts= ost->sync_opts;
+//            big_picture.pts= av_rescale(ost->sync_opts, AV_TIME_BASE*(int64_t)enc->time_base.num, enc->time_base.den);
 //av_log(NULL, AV_LOG_DEBUG, "%lld -> encoder\n", ost->sync_opts);
             ret = avcodec_encode_video(enc, 
                                        bit_buffer, bit_buffer_size,
@@ -914,10 +915,10 @@
                 pkt.data= bit_buffer;
                 pkt.size= ret;
                 if(enc->coded_frame)
-                    pkt.pts= enc->coded_frame->pts;
+                    pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
 /*av_log(NULL, AV_LOG_DEBUG, "encoder -> %lld/%lld\n", 
-   pkt.pts != AV_NOPTS_VALUE ? av_rescale(pkt.pts, enc->frame_rate, AV_TIME_BASE*(int64_t)enc->frame_rate_base) : -1,
-   pkt.dts != AV_NOPTS_VALUE ? av_rescale(pkt.dts, enc->frame_rate, AV_TIME_BASE*(int64_t)enc->frame_rate_base) : -1);*/
+   pkt.pts != AV_NOPTS_VALUE ? av_rescale(pkt.pts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1,
+   pkt.dts != AV_NOPTS_VALUE ? av_rescale(pkt.dts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1);*/
 
                 if(enc->coded_frame && enc->coded_frame->key_frame)
                     pkt.flags |= PKT_FLAG_KEY;
@@ -980,11 +981,11 @@
         
         fprintf(fvstats,"f_size= %6d ", frame_size);
         /* compute pts value */
-        ti1 = (double)ost->sync_opts *enc->frame_rate_base / enc->frame_rate;
+        ti1 = ost->sync_opts * av_q2d(enc->time_base);
         if (ti1 < 0.01)
             ti1 = 0.01;
     
-        bitrate = (double)(frame_size * 8) * enc->frame_rate / enc->frame_rate_base / 1000.0;
+        bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0;
         avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0;
         fprintf(fvstats, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ",
             (double)video_size / 1024, ti1, bitrate, avg_bitrate);
@@ -1119,7 +1120,7 @@
     if(!pkt){
         ist->pts= ist->next_pts; // needed for last packet if vsync=0
     } else if (pkt->dts != AV_NOPTS_VALUE) { //FIXME seems redundant, as libavformat does this too
-        ist->next_pts = ist->pts = pkt->dts;
+        ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);
     } else {
 //        assert(ist->pts == ist->next_pts);
     }
@@ -1175,10 +1176,10 @@
                         /* no picture yet */
                         goto discard_packet;
                     }
-                    if (ist->st->codec.frame_rate_base != 0) {
+                    if (ist->st->codec.time_base.num != 0) {
                         ist->next_pts += ((int64_t)AV_TIME_BASE * 
-                                          ist->st->codec.frame_rate_base) /
-                            ist->st->codec.frame_rate;
+                                          ist->st->codec.time_base.num) /
+                            ist->st->codec.time_base.den;
                     }
                     len = 0;
                     break;
@@ -1192,10 +1193,10 @@
                         (ist->st->codec.sample_rate * ist->st->codec.channels);
                     break;
                 case CODEC_TYPE_VIDEO:
-                    if (ist->st->codec.frame_rate_base != 0) {
+                    if (ist->st->codec.time_base.num != 0) {
                         ist->next_pts += ((int64_t)AV_TIME_BASE * 
-                                          ist->st->codec.frame_rate_base) /
-                            ist->st->codec.frame_rate;
+                                          ist->st->codec.time_base.num) /
+                            ist->st->codec.time_base.den;
                     }
                     break;
                 }
@@ -1227,7 +1228,7 @@
 
             /* frame rate emulation */
             if (ist->st->codec.rate_emu) {
-                int64_t pts = av_rescale((int64_t) ist->frame * ist->st->codec.frame_rate_base, 1000000, ist->st->codec.frame_rate);
+                int64_t pts = av_rescale((int64_t) ist->frame * ist->st->codec.time_base.num, 1000000, ist->st->codec.time_base.den);
                 int64_t now = av_gettime() - ist->start;
                 if (pts > now)
                     usleep(pts - now);
@@ -1304,10 +1305,10 @@
                             opkt.data= data_buf;
                             opkt.size= data_size;
                             if(pkt->pts != AV_NOPTS_VALUE)
-                                opkt.pts= pkt->pts + input_files_ts_offset[ist->file_index];
+                                opkt.pts= av_rescale_q(av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q) + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q,  ost->st->time_base);
                             else
                                 opkt.pts= AV_NOPTS_VALUE;
-                            opkt.dts= pkt->dts + input_files_ts_offset[ist->file_index];
+                            opkt.dts= av_rescale_q(av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q) + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q,  ost->st->time_base);
                             opkt.flags= pkt->flags;
                             
                             av_interleaved_write_frame(os, &opkt);
@@ -1363,7 +1364,7 @@
                         pkt.data= bit_buffer;
                         pkt.size= ret;
                         if(enc->coded_frame)
-                            pkt.pts= enc->coded_frame->pts;
+                            pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
                         av_interleaved_write_frame(os, &pkt);
                     }
                 }
@@ -1549,8 +1550,7 @@
                 codec->block_align= icodec->block_align;
                 break;
             case CODEC_TYPE_VIDEO:
-                codec->frame_rate = icodec->frame_rate;
-                codec->frame_rate_base = icodec->frame_rate_base;
+                codec->time_base = icodec->time_base;
                 codec->width = icodec->width;
                 codec->height = icodec->height;
                 codec->has_b_frames = icodec->has_b_frames;
@@ -1781,7 +1781,7 @@
         ist = ist_table[i];
 	is = input_files[ist->file_index];
         ist->pts = 0;
-        ist->next_pts = ist->st->start_time;
+        ist->next_pts = av_rescale_q(ist->st->start_time, ist->st->time_base, AV_TIME_BASE_Q);
         if(ist->next_pts == AV_NOPTS_VALUE) 
             ist->next_pts=0;
         if(input_files_ts_offset[ist->file_index])
@@ -1874,9 +1874,9 @@
             os = output_files[ost->file_index];
             ist = ist_table[ost->source_index];
             if(ost->st->codec.codec_type == CODEC_TYPE_VIDEO)
-                opts = (double)ost->sync_opts * ost->st->codec.frame_rate_base / ost->st->codec.frame_rate;
+                opts = ost->sync_opts * av_q2d(ost->st->codec.time_base);
             else
-                opts = (double)ost->st->pts.val * ost->st->time_base.num / ost->st->time_base.den;
+                opts = ost->st->pts.val * av_q2d(ost->st->time_base);
             ipts = (double)ist->pts;
             if (!file_table[ist->file_index].eof_reached){
                 if(ipts < ipts_min) {
@@ -1932,7 +1932,7 @@
 
 //        fprintf(stderr, "next:%lld dts:%lld off:%lld %d\n", ist->next_pts, pkt.dts, input_files_ts_offset[ist->file_index], ist->st->codec.codec_type);
         if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE) {
-            int64_t delta= pkt.dts - ist->next_pts;
+            int64_t delta= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q) - ist->next_pts;
             if(ABS(delta) > 10LL*AV_TIME_BASE && !copy_ts){
                 input_files_ts_offset[ist->file_index]-= delta;
                 if (verbose > 2)
@@ -2869,8 +2869,8 @@
     memset(ap, 0, sizeof(*ap));
     ap->sample_rate = audio_sample_rate;
     ap->channels = audio_channels;
-    ap->frame_rate = frame_rate;
-    ap->frame_rate_base = frame_rate_base;
+    ap->time_base.den = frame_rate;
+    ap->time_base.num = frame_rate_base;
     ap->width = frame_width + frame_padleft + frame_padright;
     ap->height = frame_height + frame_padtop + frame_padbottom;
     ap->image_format = image_format;
@@ -2935,8 +2935,8 @@
             frame_width = enc->width;
 	    frame_aspect_ratio = av_q2d(enc->sample_aspect_ratio) * enc->width / enc->height;
 	    frame_pix_fmt = enc->pix_fmt;
-            rfps      = ic->streams[i]->r_frame_rate;
-            rfps_base = ic->streams[i]->r_frame_rate_base;
+            rfps      = ic->streams[i]->r_frame_rate.num;
+            rfps_base = ic->streams[i]->r_frame_rate.den;
             enc->workaround_bugs = workaround_bugs;
             enc->error_resilience = error_resilience; 
             enc->error_concealment = error_concealment; 
@@ -2949,11 +2949,11 @@
             if(me_threshold)
                 enc->debug |= FF_DEBUG_MV;
 
-            if (enc->frame_rate != rfps || enc->frame_rate_base != rfps_base) { 
+            if (enc->time_base.den != rfps || enc->time_base.num != rfps_base) { 
 
                 if (verbose >= 0)
                     fprintf(stderr,"\nSeems that stream %d comes from film source: %2.2f (%d/%d) -> %2.2f (%d/%d)\n",
-                            i, (float)enc->frame_rate / enc->frame_rate_base, enc->frame_rate, enc->frame_rate_base,
+                            i, (float)enc->time_base.den / enc->time_base.num, enc->time_base.den, enc->time_base.num,
 
                     (float)rfps / rfps_base, rfps, rfps_base);
             }
@@ -3118,8 +3118,8 @@
                 
                 video_enc->bit_rate = video_bit_rate;
                 video_enc->bit_rate_tolerance = video_bit_rate_tolerance;
-                video_enc->frame_rate = frame_rate; 
-                video_enc->frame_rate_base = frame_rate_base; 
+                video_enc->time_base.den = frame_rate; 
+                video_enc->time_base.num = frame_rate_base; 
                 if(codec && codec->supported_framerates){
                     const AVRational *p= codec->supported_framerates;
                     AVRational req= (AVRational){frame_rate, frame_rate_base};
@@ -3133,8 +3133,8 @@
                             best= p;
                         }
                     }
-                    video_enc->frame_rate     = best->num;
-                    video_enc->frame_rate_base= best->den;
+                    video_enc->time_base.den= best->num;
+                    video_enc->time_base.num= best->den;
                 }
                 
                 video_enc->width = frame_width + frame_padright + frame_padleft;
@@ -3497,7 +3497,7 @@
     has_audio = 0;
     memset(ap, 0, sizeof(*ap));
     memset(vp, 0, sizeof(*vp));
-    vp->frame_rate_base= 1;
+    vp->time_base.num= 1;
     for(j=0;j<nb_output_files;j++) {
         oc = output_files[j];
         for(i=0;i<oc->nb_streams;i++) {
@@ -3516,9 +3516,8 @@
                 if (enc->height > vp->height)
                     vp->height = enc->height;
                 
-                if (vp->frame_rate_base*(int64_t)enc->frame_rate > enc->frame_rate_base*(int64_t)vp->frame_rate){
-                    vp->frame_rate      = enc->frame_rate;
-                    vp->frame_rate_base = enc->frame_rate_base;
+                if (vp->time_base.num*(int64_t)enc->time_base.den > enc->time_base.num*(int64_t)vp->time_base.den){
+                    vp->time_base = enc->time_base;
                 }
                 has_video = 1;
                 break;
@@ -3550,8 +3549,8 @@
             exit(1);
         }
         /* by now video grab has one stream */
-        ic->streams[0]->r_frame_rate      = vp->frame_rate;
-        ic->streams[0]->r_frame_rate_base = vp->frame_rate_base;
+        ic->streams[0]->r_frame_rate.num = vp->time_base.den;
+        ic->streams[0]->r_frame_rate.den = vp->time_base.num;
         input_files[nb_input_files] = ic;
 
         if (verbose >= 0)
@@ -3799,7 +3798,7 @@
                         AVCodecContext *c = &input_files[j]->streams[i]->codec;
                         if(c->codec_type != CODEC_TYPE_VIDEO)
                             continue;
-                        fr = c->frame_rate * 1000 / c->frame_rate_base;
+                        fr = c->time_base.den * 1000 / c->time_base.num;
                         if(fr == 25000) {
                             norm = 0;
                             break;

Index: ffplay.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/ffplay.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- ffplay.c	25 Apr 2005 15:13:39 -0000	1.41
+++ ffplay.c	30 Apr 2005 21:43:55 -0000	1.42
@@ -874,8 +874,7 @@
         pts = is->video_clock;
     }
     /* update video clock for next frame */
-    frame_delay = (double)is->video_st->codec.frame_rate_base / 
-        (double)is->video_st->codec.frame_rate;
+    frame_delay = av_q2d(is->video_st->codec.time_base);
     /* for MPEG2, the frame can be repeated, so we update the
        clock accordingly */
     if (src_frame->repeat_pict) {
@@ -917,7 +916,7 @@
            this packet, if any */
         pts = 0;
         if (pkt->dts != AV_NOPTS_VALUE)
-            pts = (double)pkt->dts / AV_TIME_BASE;
+            pts = av_q2d(is->video_st->time_base)*pkt->dts;
 
             SDL_LockMutex(is->video_decoder_mutex);
             len1 = avcodec_decode_video(&is->video_st->codec, 
@@ -1097,7 +1096,7 @@
         
         /* if update the audio clock with the pts */
         if (pkt->pts != AV_NOPTS_VALUE) {
-            is->audio_clock = (double)pkt->pts / AV_TIME_BASE;
+            is->audio_clock = av_q2d(is->audio_st->time_base)*pkt->pts;
         }
     }
 }

Index: ffserver.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/ffserver.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -d -r1.90 -r1.91
--- ffserver.c	3 Jan 2005 02:42:02 -0000	1.90
+++ ffserver.c	30 Apr 2005 21:43:55 -0000	1.91
@@ -1757,7 +1757,7 @@
                 case CODEC_TYPE_VIDEO:
                     type = "video";
                     snprintf(parameters, sizeof(parameters), "%dx%d, q=%d-%d, fps=%d", st->codec.width, st->codec.height,
-                                st->codec.qmin, st->codec.qmax, st->codec.frame_rate / st->codec.frame_rate_base);
+                                st->codec.qmin, st->codec.qmax, st->codec.time_base.den / st->codec.time_base.num);
                     break;
                 default:
                     av_abort();
@@ -2076,7 +2076,7 @@
                 } else {
                     /* update first pts if needed */
                     if (c->first_pts == AV_NOPTS_VALUE) {
-                        c->first_pts = pkt.dts;
+                        c->first_pts = av_rescale_q(pkt.dts, c->fmt_in->streams[pkt.stream_index]->time_base, AV_TIME_BASE_Q);
                         c->start_time = cur_time;
                     }
                     /* send it to the appropriate stream */
@@ -2125,10 +2125,10 @@
                             AVStream *st;
                             /* compute send time and duration */
                             st = c->fmt_in->streams[pkt.stream_index];
-                            c->cur_pts = pkt.dts;
+                            c->cur_pts = av_rescale_q(pkt.dts, st->time_base, AV_TIME_BASE_Q);
                             if (st->start_time != AV_NOPTS_VALUE)
-                                c->cur_pts -= st->start_time;
-                            c->cur_frame_duration = pkt.duration;
+                                c->cur_pts -= av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q);
+                            c->cur_frame_duration = av_rescale_q(pkt.duration, st->time_base, AV_TIME_BASE_Q);
 #if 0
                             printf("index=%d pts=%0.3f duration=%0.6f\n",
                                    pkt.stream_index,
@@ -3254,8 +3254,8 @@
             case CODEC_TYPE_VIDEO:
                 if (av1->width == av->width &&
                     av1->height == av->height &&
-                    av1->frame_rate == av->frame_rate &&
-                    av1->frame_rate_base == av->frame_rate_base &&
+                    av1->time_base.den == av->time_base.den &&
+                    av1->time_base.num == av->time_base.num &&
                     av1->gop_size == av->gop_size)
                     goto found;
                 break;
@@ -3452,8 +3452,8 @@
                                 printf("Codec bitrates do not match for stream %d\n", i);
                                 matches = 0;
                             } else if (ccf->codec_type == CODEC_TYPE_VIDEO) {
-                                if (CHECK_CODEC(frame_rate) ||
-                                    CHECK_CODEC(frame_rate_base) ||
+                                if (CHECK_CODEC(time_base.den) ||
+                                    CHECK_CODEC(time_base.num) ||
                                     CHECK_CODEC(width) ||
                                     CHECK_CODEC(height)) {
                                     printf("Codec width, height and framerate do not match for stream %d\n", i);
@@ -3613,9 +3613,9 @@
     case CODEC_TYPE_VIDEO:
         if (av->bit_rate == 0)
             av->bit_rate = 64000;
-        if (av->frame_rate == 0){
-            av->frame_rate = 5;
-            av->frame_rate_base = 1;
+        if (av->time_base.num == 0){
+            av->time_base.den = 5;
+            av->time_base.num = 1;
         }
         if (av->width == 0 || av->height == 0) {
             av->width = 160;
@@ -4095,8 +4095,8 @@
         } else if (!strcasecmp(cmd, "VideoFrameRate")) {
             get_arg(arg, sizeof(arg), &p);
             if (stream) {
-                video_enc.frame_rate_base= DEFAULT_FRAME_RATE_BASE;
-                video_enc.frame_rate = (int)(strtod(arg, NULL) * video_enc.frame_rate_base);
+                video_enc.time_base.num= DEFAULT_FRAME_RATE_BASE;
+                video_enc.time_base.den = (int)(strtod(arg, NULL) * video_enc.time_base.num);
             }
         } else if (!strcasecmp(cmd, "VideoGopSize")) {
             get_arg(arg, sizeof(arg), &p);

Index: output_example.c
===================================================================
RCS file: /cvsroot/ffmpeg/ffmpeg/output_example.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- output_example.c	24 Feb 2005 19:08:48 -0000	1.12
+++ output_example.c	30 Apr 2005 21:43:55 -0000	1.13
@@ -199,8 +199,8 @@
     c->width = 352;  
     c->height = 288;
     /* frames per second */
-    c->frame_rate = STREAM_FRAME_RATE;  
-    c->frame_rate_base = 1;
+    c->time_base.den = STREAM_FRAME_RATE;  
+    c->time_base.num = 1;
     c->gop_size = 12; /* emit one intra frame every twelve frames at most */
     if (c->codec_id == CODEC_ID_MPEG2VIDEO) {
         /* just for testing, we also add B frames */





More information about the ffmpeg-cvslog mailing list