Originally committed as revision 3148 to svn://svn.ffmpeg.org/ffmpeg/trunktags/v0.5
@@ -595,10 +595,10 @@ static void do_video_out(AVFormatContext *s, | |||
double adelta, vdelta, av_delay; | |||
adelta = audio_sync->sync_ipts - ((double)audio_sync->sync_opts * | |||
s->pts_num / s->pts_den); | |||
ost->st->time_base.num / ost->st->time_base.den); | |||
vdelta = ost->sync_ipts - ((double)ost->sync_opts * | |||
s->pts_num / s->pts_den); | |||
ost->st->time_base.num / ost->st->time_base.den); | |||
av_delay = adelta - vdelta; | |||
if (av_delay < -AV_DELAY_MAX) | |||
@@ -609,7 +609,7 @@ static void do_video_out(AVFormatContext *s, | |||
} else { | |||
double vdelta; | |||
vdelta = (double)(ost->st->pts.val) * s->pts_num / s->pts_den - (ost->sync_ipts - ost->sync_ipts_offset); | |||
vdelta = (double)(ost->st->pts.val) * ost->st->time_base.num / ost->st->time_base.den - (ost->sync_ipts - ost->sync_ipts_offset); | |||
if (vdelta < 100 && vdelta > -100 && ost->sync_ipts_offset) { | |||
if (vdelta < -AV_DELAY_MAX) | |||
nb_frames = 2; | |||
@@ -630,10 +630,10 @@ static void do_video_out(AVFormatContext *s, | |||
if (audio_sync && verbose >=0) { | |||
fprintf(stderr, "Input APTS %12.6f, output APTS %12.6f, ", | |||
(double) audio_sync->sync_ipts, | |||
(double) audio_sync->st->pts.val * s->pts_num / s->pts_den); | |||
(double) audio_sync->st->pts.val * st->time_base.num / st->time_base.den); | |||
fprintf(stderr, "Input VPTS %12.6f, output VPTS %12.6f: %s\n", | |||
(double) ost->sync_ipts, | |||
(double) ost->st->pts.val * s->pts_num / s->pts_den, | |||
(double) ost->st->pts.val * st->time_base.num / st->time_base.den, | |||
action[nb_frames]); | |||
} | |||
} | |||
@@ -872,7 +872,7 @@ static void do_video_stats(AVFormatContext *os, AVOutputStream *ost, | |||
fprintf(fvstats,"f_size= %6d ", frame_size); | |||
/* compute pts value */ | |||
ti1 = (double)ost->st->pts.val * os->pts_num / os->pts_den; | |||
ti1 = (double)ost->st->pts.val * ost->st->time_base.num / ost->st->time_base.den; | |||
if (ti1 < 0.01) | |||
ti1 = 0.01; | |||
@@ -956,7 +956,7 @@ static void print_report(AVFormatContext **output_files, | |||
vid = 1; | |||
} | |||
/* compute min output value */ | |||
pts = (double)ost->st->pts.val * os->pts_num / os->pts_den; | |||
pts = (double)ost->st->pts.val * ost->st->time_base.num / ost->st->time_base.den; | |||
if ((pts < ti1) && (pts > 0)) | |||
ti1 = pts; | |||
} | |||
@@ -1118,7 +1118,7 @@ static int output_packet(AVInputStream *ist, int ist_index, | |||
printf("%d: got pts=%0.3f %0.3f\n", i, | |||
(double)pkt->pts / AV_TIME_BASE, | |||
((double)ist->pts / AV_TIME_BASE) - | |||
((double)ost->st->pts.val * os->pts_num / os->pts_den)); | |||
((double)ost->st->pts.val * ost->time_base.num / ost->time_base.den)); | |||
#endif | |||
/* set the input output pts pairs */ | |||
ost->sync_ipts = (double)ist->pts / AV_TIME_BASE; | |||
@@ -1165,7 +1165,7 @@ static int output_packet(AVInputStream *ist, int ist_index, | |||
avcodec_get_frame_defaults(&avframe); | |||
ost->st->codec.coded_frame= &avframe; | |||
avframe.key_frame = pkt->flags & PKT_FLAG_KEY; | |||
ost->st->pts.val= av_rescale(ist->pts, os->pts_den, os->pts_num*AV_TIME_BASE); | |||
ost->st->pts.val= av_rescale(ist->pts, ost->st->time_base.den, ost->st->time_base.num*AV_TIME_BASE); | |||
if(ost->st->codec.codec_type == CODEC_TYPE_AUDIO) | |||
audio_size += data_size; | |||
@@ -1637,7 +1637,7 @@ static int av_encode(AVFormatContext **output_files, | |||
ost = ost_table[i]; | |||
os = output_files[ost->file_index]; | |||
ist = ist_table[ost->source_index]; | |||
pts = (double)ost->st->pts.val * os->pts_num / os->pts_den; | |||
pts = (double)ost->st->pts.val * ost->st->time_base.num / ost->st->time_base.den; | |||
if (!file_table[ist->file_index].eof_reached && | |||
pts < pts_min) { | |||
pts_min = pts; | |||
@@ -2729,12 +2729,11 @@ static void opt_output_file(const char *filename) | |||
if (use_video) { | |||
AVCodecContext *video_enc; | |||
st = av_mallocz(sizeof(AVStream)); | |||
st = av_new_stream(oc, nb_streams++); | |||
if (!st) { | |||
fprintf(stderr, "Could not alloc stream\n"); | |||
exit(1); | |||
} | |||
avcodec_get_context_defaults(&st->codec); | |||
#if defined(HAVE_PTHREADS) || defined(HAVE_W32THREADS) | |||
if(thread_count>1) | |||
avcodec_thread_init(&st->codec, thread_count); | |||
@@ -2960,19 +2959,16 @@ static void opt_output_file(const char *filename) | |||
} | |||
} | |||
} | |||
oc->streams[nb_streams] = st; | |||
nb_streams++; | |||
} | |||
if (use_audio) { | |||
AVCodecContext *audio_enc; | |||
st = av_mallocz(sizeof(AVStream)); | |||
st = av_new_stream(oc, nb_streams++); | |||
if (!st) { | |||
fprintf(stderr, "Could not alloc stream\n"); | |||
exit(1); | |||
} | |||
avcodec_get_context_defaults(&st->codec); | |||
#if defined(HAVE_PTHREADS) || defined(HAVE_W32THREADS) | |||
if(thread_count>1) | |||
avcodec_thread_init(&st->codec, thread_count); | |||
@@ -3002,8 +2998,6 @@ static void opt_output_file(const char *filename) | |||
} else | |||
audio_enc->channels = audio_channels; | |||
} | |||
oc->streams[nb_streams] = st; | |||
nb_streams++; | |||
} | |||
oc->nb_streams = nb_streams; | |||
@@ -164,6 +164,7 @@ static int fourxm_read_header(AVFormatContext *s, | |||
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 @@ static int fourxm_read_header(AVFormatContext *s, | |||
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 @@ static int fourxm_read_header(AVFormatContext *s, | |||
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; | |||
} | |||
@@ -285,6 +285,8 @@ static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data | |||
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 @@ static int asf_write_header(AVFormatContext *s) | |||
{ | |||
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; | |||
@@ -148,8 +148,6 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) | |||
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 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) | |||
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; | |||
@@ -230,7 +230,7 @@ static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap) | |||
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; | |||
} | |||
@@ -214,6 +214,8 @@ typedef struct AVStream { | |||
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 @@ typedef struct AVStream { | |||
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 @@ typedef struct AVFormatContext { | |||
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 @@ typedef struct AVFormatContext { | |||
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_play(AVFormatContext *s); | |||
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); | |||
@@ -93,8 +93,6 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) | |||
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 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) | |||
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; | |||
@@ -550,6 +550,7 @@ static int dv_extract_audio_info(DVDemuxContext* c, uint8_t* frame) | |||
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 @@ DVDemuxContext* dv_init_demux(AVFormatContext *s) | |||
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 @@ DVDemuxContext* dv_init_demux(AVFormatContext *s) | |||
s->ctx_flags |= AVFMTCTX_NOHEADER; | |||
av_set_pts_info(s, 64, 1, 30000); | |||
return c; | |||
fail: | |||
@@ -100,9 +100,7 @@ static int flic_read_header(AVFormatContext *s, | |||
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, | |||
@@ -48,8 +48,6 @@ static int flv_read_header(AVFormatContext *s, | |||
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 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) | |||
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; | |||
@@ -134,8 +134,6 @@ static int flv_write_header(AVFormatContext *s) | |||
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 @@ static int flv_write_header(AVFormatContext *s) | |||
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 | |||
@@ -79,6 +79,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) | |||
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 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) | |||
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: | |||
@@ -154,6 +154,7 @@ static int idcin_read_header(AVFormatContext *s, | |||
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 @@ static int idcin_read_header(AVFormatContext *s, | |||
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 @@ static int idcin_read_header(AVFormatContext *s, | |||
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; | |||
} | |||
@@ -84,10 +84,6 @@ static int roq_read_header(AVFormatContext *s, | |||
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 @@ static int roq_read_header(AVFormatContext *s, | |||
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 @@ static int roq_read_header(AVFormatContext *s, | |||
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; | |||
@@ -236,7 +236,7 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) | |||
} 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; | |||
@@ -552,14 +552,11 @@ static int ipmovie_read_header(AVFormatContext *s, | |||
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 @@ static int ipmovie_read_header(AVFormatContext *s, | |||
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; | |||
@@ -2152,8 +2152,6 @@ matroska_read_header (AVFormatContext *s, | |||
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 @@ matroska_read_header (AVFormatContext *s, | |||
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; | |||
@@ -768,6 +768,7 @@ static void mpegts_push_data(void *opaque, | |||
} | |||
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 @@ static int mpegts_read_header(AVFormatContext *s, | |||
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; | |||
@@ -511,8 +511,6 @@ static int nut_write_header(AVFormatContext *s) | |||
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 @@ static int nut_write_header(AVFormatContext *s) | |||
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 @@ static int decode_stream_header(NUTContext *nut){ | |||
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 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap) | |||
nut->avf= s; | |||
av_set_pts_info(s, 60, 1, AV_TIME_BASE); | |||
/* main header */ | |||
pos=0; | |||
for(;;){ | |||
@@ -36,14 +36,14 @@ static int ogg_write_header(AVFormatContext *avfcontext) | |||
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 @@ static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap) | |||
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 @@ static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap) | |||
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; | |||
@@ -135,9 +135,6 @@ static int str_read_header(AVFormatContext *s, | |||
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 @@ static int str_read_header(AVFormatContext *s, | |||
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 @@ static int str_read_header(AVFormatContext *s, | |||
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; | |||
@@ -173,6 +173,9 @@ static int film_read_header(AVFormatContext *s, | |||
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 @@ static int film_read_header(AVFormatContext *s, | |||
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; | |||
} | |||
@@ -129,6 +129,7 @@ static int vmd_read_header(AVFormatContext *s, | |||
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 @@ static int vmd_read_header(AVFormatContext *s, | |||
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 @@ static int vmd_read_header(AVFormatContext *s, | |||
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; | |||
@@ -805,8 +805,6 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap) | |||
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 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap) | |||
/* 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 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap) | |||
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; | |||
@@ -355,13 +355,6 @@ int av_open_input_stream(AVFormatContext **ic_ptr, | |||
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 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt) | |||
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 @@ static inline int64_t convert_timestamp_units(AVFormatContext *s, | |||
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 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) | |||
/* 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 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) | |||
(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 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic) | |||
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 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic) | |||
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 @@ AVStream *av_new_stream(AVFormatContext *s, int id) | |||
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 av_write_header(AVFormatContext *s) | |||
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 @@ int av_write_header(AVFormatContext *s) | |||
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 av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf, | |||
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 @@ int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf, | |||
/* 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 @@ void url_split(char *proto, int proto_size, | |||
* @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 */ | |||
@@ -233,6 +233,7 @@ static int wc3_read_header(AVFormatContext *s, | |||
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 @@ static int wc3_read_header(AVFormatContext *s, | |||
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 @@ static int wc3_read_header(AVFormatContext *s, | |||
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; | |||
} | |||
@@ -131,14 +131,11 @@ static int wsaud_read_header(AVFormatContext *s, | |||
/* 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 @@ static int wsvqa_read_header(AVFormatContext *s, | |||
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 @@ static int wsvqa_read_header(AVFormatContext *s, | |||
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 */ | |||