Commit c0df9d75 authored by Michael Niedermayer's avatar Michael Niedermayer

switch to native time bases

Originally committed as revision 4168 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent b7782b47
......@@ -556,7 +556,7 @@ static void do_audio_out(AVFormatContext *s,
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 @@ static void do_audio_out(AVFormatContext *s,
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 @@ static void do_video_out(AVFormatContext *s,
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 @@ static void do_video_out(AVFormatContext *s,
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 @@ static void do_video_out(AVFormatContext *s,
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 @@ static void do_video_out(AVFormatContext *s,
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 @@ static void do_video_out(AVFormatContext *s,
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 @@ static void do_video_stats(AVFormatContext *os, AVOutputStream *ost,
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 @@ static int output_packet(AVInputStream *ist, int ist_index,
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 @@ static int output_packet(AVInputStream *ist, int ist_index,
/* 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 @@ static int output_packet(AVInputStream *ist, int ist_index,
(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 @@ static int output_packet(AVInputStream *ist, int ist_index,
/* 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 @@ static int output_packet(AVInputStream *ist, int ist_index,
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 @@ static int output_packet(AVInputStream *ist, int ist_index,
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 @@ static int av_encode(AVFormatContext **output_files,
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 @@ static int av_encode(AVFormatContext **output_files,
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 @@ static int av_encode(AVFormatContext **output_files,
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 @@ static int av_encode(AVFormatContext **output_files,
// 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 @@ static void opt_input_file(const char *filename)
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 @@ static void opt_input_file(const char *filename)
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 @@ static void opt_input_file(const char *filename)
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 @@ static void opt_output_file(const char *filename)
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 @@ static void opt_output_file(const char *filename)
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 @@ static void prepare_grab(void)
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 @@ static void prepare_grab(void)
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 @@ static void prepare_grab(void)
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 @@ static void opt_target(const char *arg)
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;
......
......@@ -874,8 +874,7 @@ static int output_picture2(VideoState *is, AVFrame *src_frame, double pts1)
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 @@ static int video_thread(void *arg)
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 @@ static int audio_decode_frame(VideoState *is, uint8_t *audio_buf, double *pts_pt
/* 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;
}
}
}
......
......@@ -1757,7 +1757,7 @@ static void compute_stats(HTTPContext *c)
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 @@ static int http_prepare_data(HTTPContext *c)
} 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 @@ static int http_prepare_data(HTTPContext *c)
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 @@ static int add_av_stream(FFStream *feed, AVStream *st)
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 @@ static void build_feed_streams(void)
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 @@ static void add_codec(FFStream *stream, AVCodecContext *av)
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 @@ static int parse_ffconfig(const char *filename)
} 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);
......
......@@ -195,8 +195,7 @@ void video_encode_example(const char *filename)
c->width = 352;
c->height = 288;
/* frames per second */
c->frame_rate = 25;
c->frame_rate_base= 1;
c->time_base= (AVRational){1,25};
c->gop_size = 10; /* emit one intra frame every ten frames */
c->max_b_frames=1;
......
......@@ -17,7 +17,7 @@ extern "C" {
#define FFMPEG_VERSION_INT 0x000409
#define FFMPEG_VERSION "0.4.9-pre1"
#define LIBAVCODEC_BUILD 4753
#define LIBAVCODEC_BUILD 4754
#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVCODEC_VERSION FFMPEG_VERSION
......@@ -28,6 +28,7 @@ extern "C" {
#define AV_NOPTS_VALUE int64_t_C(0x8000000000000000)
#define AV_TIME_BASE 1000000
#define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE}
enum CodecID {
CODEC_ID_NONE,
......@@ -442,8 +443,8 @@ typedef struct AVPanScan{
int pict_type;\
\
/**\
* presentation timestamp in AV_TIME_BASE (=micro seconds currently) (time when frame should be shown to user)\
* if AV_NOPTS_VALUE then the frame_rate will be used as reference\
* presentation timestamp in time_base units (time when frame should be shown to user)\
* if AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed\
* - encoding: MUST be set by user\
* - decoding: set by lavc\
*/\
......@@ -721,13 +722,11 @@ typedef struct AVCodecContext {
/* video only */
/**
* frames per sec multiplied by frame_rate_base.
* for variable fps this is the precission, so if the timestamps
* can be specified in msec precssion then this is 1000*frame_rate_base
* time base in which the timestamps are specified.
* - encoding: MUST be set by user
* - decoding: set by lavc. 0 or the frame_rate if available
* - decoding: set by lavc.
*/
int frame_rate;
AVRational time_base;
/**
* picture width / height.
......@@ -1420,15 +1419,6 @@ typedef struct AVCodecContext {
*/
int me_range;
/**
* frame_rate_base.
* for variable fps this is 1
* - encoding: set by user.
* - decoding: set by lavc.
* @todo move this after frame_rate
*/
int frame_rate_base;
/**
* intra quantizer bias.
* - encoding: set by user.
......@@ -2244,6 +2234,11 @@ int64_t av_rescale(int64_t a, int64_t b, int64_t c);
*/
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding);
/**
* rescale a 64bit integer by 2 rational numbers.
*/
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq);
/* frame parsing */
typedef struct AVCodecParserContext {
void *priv_data;
......
......@@ -103,8 +103,8 @@ void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number){
put_bits(&s->pb, 20, 0x10); /* PSC */
temp_ref= s->picture_number * (int64_t)30000 * s->avctx->frame_rate_base /
(1001 * (int64_t)s->avctx->frame_rate);
temp_ref= s->picture_number * (int64_t)30000 * s->avctx->time_base.num /
(1001 * (int64_t)s->avctx->time_base.den); //FIXME maybe this should use a timestamp
put_bits(&s->pb, 5, temp_ref & 0x1f); /* TemporalReference */
put_bits(&s->pb, 1, 0); /* split screen off */
......
......@@ -160,8 +160,8 @@ void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number)
put_bits(&s->pb, 17, 1);
put_bits(&s->pb, 5, (s->h263_flv-1)); /* 0: h263 escape codes 1: 11-bit escape codes */
put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->frame_rate_base) /
s->avctx->frame_rate) & 0xff); /* TemporalReference */
put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->time_base.num) / //FIXME use timestamp
s->avctx->time_base.den) & 0xff); /* TemporalReference */
if (s->width == 352 && s->height == 288)
format = 2;
else if (s->width == 176 && s->height == 144)
......@@ -208,9 +208,9 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number)
if(s->h263_plus){
for(i=0; i<2; i++){
int div, error;
div= (s->avctx->frame_rate_base*1800000LL + 500LL*s->avctx->frame_rate) / ((1000LL+i)*s->avctx->frame_rate);
div= (s->avctx->time_base.num*1800000LL + 500LL*s->avctx->time_base.den) / ((1000LL+i)*s->avctx->time_base.den);
div= clip(1, div, 127);
error= ABS(s->avctx->frame_rate_base*1800000LL - (1000LL+i)*s->avctx->frame_rate*div);
error= ABS(s->avctx->time_base.num*1800000LL - (1000LL+i)*s->avctx->time_base.den*div);
if(error < best_error){
best_error= error;
best_divisor= div;
......@@ -227,8 +227,8 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number)
/* Update the pointer to last GOB */
s->ptr_lastgob = pbBufPtr(&s->pb);
put_bits(&s->pb, 22, 0x20); /* PSC */
temp_ref= s->picture_number * (int64_t)coded_frame_rate * s->avctx->frame_rate_base /
(coded_frame_rate_base * (int64_t)s->avctx->frame_rate);
temp_ref= s->picture_number * (int64_t)coded_frame_rate * s->avctx->time_base.num / //FIXME use timestamp
(coded_frame_rate_base * (int64_t)s->avctx->time_base.den);
put_bits(&s->pb, 8, temp_ref & 0xff); /* TemporalReference */
put_bits(&s->pb, 1, 1); /* marker */
......@@ -2210,10 +2210,10 @@ void ff_set_mpeg4_time(MpegEncContext * s, int picture_number){
int time_div, time_mod;
assert(s->current_picture_ptr->pts != AV_NOPTS_VALUE);
s->time= (s->current_picture_ptr->pts*s->time_increment_resolution + AV_TIME_BASE/2)/AV_TIME_BASE;
s->time= s->current_picture_ptr->pts*s->avctx->time_base.num;
time_div= s->time/s->time_increment_resolution;
time_mod= s->time%s->time_increment_resolution;
time_div= s->time/s->avctx->time_base.den;
time_mod= s->time%s->avctx->time_base.den;
if(s->pict_type==B_TYPE){
s->pb_time= s->pp_time - (s->last_non_b_time - s->time);
......@@ -2237,9 +2237,9 @@ static void mpeg4_encode_gop_header(MpegEncContext * s){
time= s->current_picture_ptr->pts;
if(s->reordered_input_picture[1])
time= FFMIN(time, s->reordered_input_picture[1]->pts);
time= (time*s->time_increment_resolution + AV_TIME_BASE/2)/AV_TIME_BASE;
time= time*s->avctx->time_base.num;
seconds= time/s->time_increment_resolution;
seconds= time/s->avctx->time_base.den;
minutes= seconds/60; seconds %= 60;
hours= minutes/60; minutes %= 60;
hours%=24;
......@@ -2252,7 +2252,7 @@ static void mpeg4_encode_gop_header(MpegEncContext * s){
put_bits(&s->pb, 1, !!(s->flags&CODEC_FLAG_CLOSED_GOP));
put_bits(&s->pb, 1, 0); //broken link == NO
s->last_time_base= time / s->time_increment_resolution;
s->last_time_base= time / s->avctx->time_base.den;
ff_mpeg4_stuffing(&s->pb);
}
......@@ -2349,7 +2349,7 @@ static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_n
put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */
put_bits(&s->pb, 1, 1); /* marker bit */
put_bits(&s->pb, 16, s->time_increment_resolution);
put_bits(&s->pb, 16, s->avctx->time_base.den);
if (s->time_increment_bits < 1)
s->time_increment_bits = 1;
put_bits(&s->pb, 1, 1); /* marker bit */
......@@ -2420,14 +2420,14 @@ void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
s->partitioned_frame= s->data_partitioning && s->pict_type!=B_TYPE;
//printf("num:%d rate:%d base:%d\n", s->picture_number, s->frame_rate, FRAME_RATE_BASE);
//printf("num:%d rate:%d base:%d\n", s->picture_number, s->time_base.den, FRAME_RATE_BASE);
put_bits(&s->pb, 16, 0); /* vop header */
put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */
put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */
time_div= s->time/s->time_increment_resolution;
time_mod= s->time%s->time_increment_resolution;
time_div= s->time/s->avctx->time_base.den;
time_mod= s->time%s->avctx->time_base.den;
time_incr= time_div - s->last_time_base;
assert(time_incr >= 0);
while(time_incr--)
......@@ -5054,8 +5054,7 @@ int h263_decode_picture_header(MpegEncContext *s)
s->width = width;
s->height = height;
s->avctx->sample_aspect_ratio= (AVRational){12,11};
s->avctx->frame_rate = 30000;
s->avctx->frame_rate_base= 1001;
s->avctx->time_base= (AVRational){1001, 30000};