Merge remote-tracking branch 'qatar/master'

* qatar/master:
  flvdec: remove spurious use of stream id
  lavf: deprecate r_frame_rate.
  lavf: round estimated average fps to a "standard" fps.

Conflicts:
	ffmpeg.c
	ffprobe.c
	libavformat/avformat.h
	libavformat/electronicarts.c
	libavformat/flvdec.c
	libavformat/rawdec.c
	libavformat/utils.c
	tests/ref/fate/iv8-demux

Merged-by: Michael Niedermayer <michaelni@gmx.at>
pull/28/head
Michael Niedermayer 12 years ago
commit 7d1918affe
  1. 1
      ffmpeg.c
  2. 2
      libavformat/avformat.h
  3. 7
      libavformat/avisynth.c
  4. 6
      libavformat/avs.c
  5. 4
      libavformat/electronicarts.c
  6. 14
      libavformat/flvdec.c
  7. 6
      libavformat/flvenc.c
  8. 6
      libavformat/matroskadec.c
  9. 2
      libavformat/mov.c
  10. 5
      libavformat/nuv.c
  11. 22
      libavformat/r3d.c
  12. 6
      libavformat/rmdec.c
  13. 25
      libavformat/utils.c
  14. 4
      libavformat/vc1testenc.c
  15. 3
      libavformat/version.h

@ -3083,6 +3083,7 @@ static int transcode_init(void)
ost->frame_rate = av_buffersink_get_frame_rate(ost->filter->filter);
if (ist && !ost->frame_rate.num)
ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25, 1};
// ost->frame_rate = ist->st->avg_frame_rate.num ? ist->st->avg_frame_rate : (AVRational){25, 1};
if (ost->enc && ost->enc->supported_framerates && !ost->force_fps) {
int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates);
ost->frame_rate = ost->enc->supported_framerates[idx];

@ -648,6 +648,7 @@ typedef struct AVStream {
* not actually used for encoding.
*/
AVCodecContext *codec;
#if FF_API_R_FRAME_RATE
/**
* Real base framerate of the stream.
* This is the lowest framerate with which all timestamps can be
@ -657,6 +658,7 @@ typedef struct AVStream {
* approximately 3600 or 1800 timer ticks, then r_frame_rate will be 50/1.
*/
AVRational r_frame_rate;
#endif
void *priv_data;
/**

@ -120,8 +120,11 @@ static int avisynth_read_header(AVFormatContext *s)
st = avformat_new_stream(s, NULL);
st->id = id;
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
st->r_frame_rate.num = stream->info.dwRate;
st->r_frame_rate.den = stream->info.dwScale;
st->avg_frame_rate.num = stream->info.dwRate;
st->avg_frame_rate.den = stream->info.dwScale;
#if FF_API_R_FRAME_RATE
st->r_frame_rate = st->avg_frame_rate;
#endif
st->codec->width = imgfmt.bmiHeader.biWidth;
st->codec->height = imgfmt.bmiHeader.biHeight;

@ -188,8 +188,10 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt)
avs->st_video->codec->height = avs->height;
avs->st_video->codec->bits_per_coded_sample=avs->bits_per_sample;
avs->st_video->nb_frames = avs->nb_frames;
avs->st_video->r_frame_rate = avs->st_video->avg_frame_rate =
(AVRational){avs->fps, 1};
#if FF_API_R_FRAME_RATE
avs->st_video->r_frame_rate =
#endif
avs->st_video->avg_frame_rate = (AVRational){avs->fps, 1};
}
return avs_read_video_packet(s, pkt, type, sub_type, size,
palette, palette_size);

@ -439,8 +439,8 @@ static int ea_read_header(AVFormatContext *s)
st->duration = st->nb_frames = ea->nb_frames;
if (ea->time_base.num)
avpriv_set_pts_info(st, 64, ea->time_base.num, ea->time_base.den);
st->r_frame_rate = st->avg_frame_rate = (AVRational){ea->time_base.den,
ea->time_base.num};
st->r_frame_rate =
st->avg_frame_rate = (AVRational){ea->time_base.den, ea->time_base.num};
}
if (ea->audio_codec) {

@ -65,11 +65,11 @@ static int flv_probe(AVProbeData *p)
return 0;
}
static AVStream *create_stream(AVFormatContext *s, int tag, int codec_type){
static AVStream *create_stream(AVFormatContext *s, int codec_type)
{
AVStream *st = avformat_new_stream(s, NULL);
if (!st)
return NULL;
st->id = tag;
st->codec->codec_type = codec_type;
if(s->nb_streams>=3 ||( s->nb_streams==2
&& s->streams[0]->codec->codec_type != AVMEDIA_TYPE_DATA
@ -402,7 +402,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst
else if (!strcmp(key, "audiodatarate") && acodec && 0 <= (int)(num_val * 1024.0))
acodec->bit_rate = num_val * 1024.0;
else if (!strcmp(key, "datastream")) {
AVStream *st = create_stream(s, 2, AVMEDIA_TYPE_DATA);
AVStream *st = create_stream(s, AVMEDIA_TYPE_DATA);
if (!st)
return AVERROR(ENOMEM);
st->codec->codec_id = CODEC_ID_TEXT;
@ -509,11 +509,11 @@ static int flv_read_header(AVFormatContext *s)
s->ctx_flags |= AVFMTCTX_NOHEADER;
if(flags & FLV_HEADER_FLAG_HASVIDEO){
if(!create_stream(s, 0, AVMEDIA_TYPE_VIDEO))
if(!create_stream(s, AVMEDIA_TYPE_VIDEO))
return AVERROR(ENOMEM);
}
if(flags & FLV_HEADER_FLAG_HASAUDIO){
if(!create_stream(s, 1, AVMEDIA_TYPE_AUDIO))
if(!create_stream(s, AVMEDIA_TYPE_AUDIO))
return AVERROR(ENOMEM);
}
// Flag doesn't indicate whether or not there is script-data present. Must
@ -617,7 +617,7 @@ static int flv_data_packet(AVFormatContext *s, AVPacket *pkt,
}
if (i == s->nb_streams) {
st = create_stream(s, 2, AVMEDIA_TYPE_DATA);
st = create_stream(s, AVMEDIA_TYPE_DATA);
if (!st)
goto out;
st->codec->codec_id = CODEC_ID_TEXT;
@ -727,7 +727,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
}
if(i == s->nb_streams){
av_log(s, AV_LOG_WARNING, "Stream discovered after head already parsed\n");
st = create_stream(s, stream_type,
st = create_stream(s,
(int[]){AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO, AVMEDIA_TYPE_DATA}[stream_type]);
}
av_dlog(s, "%d %X %d \n", stream_type, flags, st->discard);

@ -205,9 +205,9 @@ static int flv_write_header(AVFormatContext *s)
FLVStreamContext *sc;
switch (enc->codec_type) {
case AVMEDIA_TYPE_VIDEO:
if (s->streams[i]->r_frame_rate.den &&
s->streams[i]->r_frame_rate.num) {
framerate = av_q2d(s->streams[i]->r_frame_rate);
if (s->streams[i]->avg_frame_rate.den &&
s->streams[i]->avg_frame_rate.num) {
framerate = av_q2d(s->streams[i]->avg_frame_rate);
} else {
framerate = 1 / av_q2d(s->streams[i]->codec->time_base);
}

@ -1705,9 +1705,11 @@ static int matroska_read_header(AVFormatContext *s)
255);
st->need_parsing = AVSTREAM_PARSE_HEADERS;
if (track->default_duration) {
av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den,
av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,
1000000000, track->default_duration, 30000);
st->avg_frame_rate = st->r_frame_rate;
#if FF_API_R_FRAME_RATE
st->r_frame_rate = st->avg_frame_rate;
#endif
}
/* export stereo mode flag as metadata tag */

@ -2085,9 +2085,11 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,
sc->time_scale*st->nb_frames, st->duration, INT_MAX);
#if FF_API_R_FRAME_RATE
if (sc->stts_count == 1 || (sc->stts_count == 2 && sc->stts_data[1].count == 1))
av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den,
sc->time_scale, sc->stts_data[0].duration, INT_MAX);
#endif
}
switch (st->codec->codec_id) {

@ -163,7 +163,10 @@ static int nuv_header(AVFormatContext *s) {
vst->codec->height = height;
vst->codec->bits_per_coded_sample = 10;
vst->sample_aspect_ratio = av_d2q(aspect * height / width, 10000);
vst->r_frame_rate = av_d2q(fps, 60000);
#if FF_API_R_FRAME_RATE
vst->r_frame_rate =
#endif
vst->avg_frame_rate = av_d2q(fps, 60000);
avpriv_set_pts_info(vst, 32, 1, 1000);
} else
ctx->v_id = -1;

@ -87,8 +87,12 @@ static int r3d_read_red1(AVFormatContext *s)
framerate.num = avio_rb16(s->pb);
framerate.den = avio_rb16(s->pb);
if (framerate.num && framerate.den)
st->r_frame_rate = st->avg_frame_rate = framerate;
if (framerate.num && framerate.den) {
#if FF_API_R_FRAME_RATE
st->r_frame_rate =
#endif
st->avg_frame_rate = framerate;
}
tmp = avio_r8(s->pb); // audio channels
av_dlog(s, "audio channels %d\n", tmp);
@ -135,10 +139,10 @@ static int r3d_read_rdvo(AVFormatContext *s, Atom *atom)
av_dlog(s, "video offset %d: %#x\n", i, r3d->video_offsets[i]);
}
if (st->r_frame_rate.num)
if (st->avg_frame_rate.num)
st->duration = av_rescale_q(r3d->video_offsets_count,
(AVRational){st->r_frame_rate.den,
st->r_frame_rate.num},
(AVRational){st->avg_frame_rate.den,
st->avg_frame_rate.num},
st->time_base);
av_dlog(s, "duration %"PRId64"\n", st->duration);
@ -262,9 +266,9 @@ static int r3d_read_redv(AVFormatContext *s, AVPacket *pkt, Atom *atom)
pkt->stream_index = 0;
pkt->dts = dts;
if (st->r_frame_rate.num)
if (st->avg_frame_rate.num)
pkt->duration = (uint64_t)st->time_base.den*
st->r_frame_rate.den/st->r_frame_rate.num;
st->avg_frame_rate.den/st->avg_frame_rate.num;
av_dlog(s, "pkt dts %"PRId64" duration %d\n", pkt->dts, pkt->duration);
return 0;
@ -362,11 +366,11 @@ static int r3d_seek(AVFormatContext *s, int stream_index, int64_t sample_time, i
R3DContext *r3d = s->priv_data;
int frame_num;
if (!st->r_frame_rate.num)
if (!st->avg_frame_rate.num)
return -1;
frame_num = av_rescale_q(sample_time, st->time_base,
(AVRational){st->r_frame_rate.den, st->r_frame_rate.num});
(AVRational){st->avg_frame_rate.den, st->avg_frame_rate.num});
av_dlog(s, "seek frame num %d timestamp %"PRId64"\n",
frame_num, sample_time);

@ -345,9 +345,11 @@ ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVIOContext *pb,
if ((ret = rm_read_extradata(pb, st->codec, codec_data_size - (avio_tell(pb) - codec_pos))) < 0)
return ret;
av_reduce(&st->r_frame_rate.den, &st->r_frame_rate.num,
av_reduce(&st->avg_frame_rate.den, &st->avg_frame_rate.num,
0x10000, fps, (1 << 30) - 1);
st->avg_frame_rate = st->r_frame_rate;
#if FF_API_R_FRAME_RATE
st->r_frame_rate = st->avg_frame_rate;
#endif
}
skip:

@ -2556,7 +2556,9 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
}
for (i=0; i<ic->nb_streams; i++) {
#if FF_API_R_FRAME_RATE
ic->streams[i]->info->last_dts = AV_NOPTS_VALUE;
#endif
ic->streams[i]->info->fps_first_dts = AV_NOPTS_VALUE;
ic->streams[i]->info->fps_last_dts = AV_NOPTS_VALUE;
}
@ -2676,6 +2678,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
}
st->info->codec_info_duration += pkt->duration;
}
#if FF_API_R_FRAME_RATE
{
int64_t last = st->info->last_dts;
@ -2703,6 +2706,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
if (last == AV_NOPTS_VALUE || st->info->duration_count <= 1)
st->info->last_dts = pkt->dts;
}
#endif
if(st->parser && st->parser->parser->split && !st->codec->extradata){
int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);
if (i > 0 && i < FF_MAX_EXTRADATA_SIZE) {
@ -2784,9 +2788,28 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
/* estimate average framerate if not set by demuxer */
if (st->codec_info_nb_frames>2 && !st->avg_frame_rate.num && st->info->codec_info_duration) {
int best_fps = 0;
double best_error = 0.01;
av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,
(st->codec_info_nb_frames-2)*(int64_t)st->time_base.den,
st->info->codec_info_duration*(int64_t)st->time_base.num, 60000);
/* round guessed framerate to a "standard" framerate if it's
* within 1% of the original estimate*/
for (j = 1; j < MAX_STD_TIMEBASES; j++) {
AVRational std_fps = (AVRational){get_std_framerate(j), 12*1001};
double error = fabs(av_q2d(st->avg_frame_rate) / av_q2d(std_fps) - 1);
if (error < best_error) {
best_error = error;
best_fps = std_fps.num;
}
}
if (best_fps) {
av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,
best_fps, 12*1001, INT_MAX);
}
}
// the check for tb_unreliable() is not completely correct, since this is not about handling
// a unreliable/inexact time base, but a time base that is finer than necessary, as e.g.
@ -3835,8 +3858,10 @@ static void dump_stream_format(AVFormatContext *ic, int i, int index, int is_out
if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){
if(st->avg_frame_rate.den && st->avg_frame_rate.num)
print_fps(av_q2d(st->avg_frame_rate), "fps");
#if FF_API_R_FRAME_RATE
if(st->r_frame_rate.den && st->r_frame_rate.num)
print_fps(av_q2d(st->r_frame_rate), "tbr");
#endif
if(st->time_base.den && st->time_base.num)
print_fps(1/av_q2d(st->time_base), "tbn");
if(st->codec->time_base.den && st->codec->time_base.num)

@ -44,8 +44,8 @@ static int vc1test_write_header(AVFormatContext *s)
avio_wl24(pb, 0); // hrd_buffer
avio_w8(pb, 0x80); // level|cbr|res1
avio_wl32(pb, 0); // hrd_rate
if (s->streams[0]->r_frame_rate.den && s->streams[0]->r_frame_rate.num == 1)
avio_wl32(pb, s->streams[0]->r_frame_rate.den);
if (s->streams[0]->avg_frame_rate.den && s->streams[0]->avg_frame_rate.num == 1)
avio_wl32(pb, s->streams[0]->avg_frame_rate.den);
else
avio_wl32(pb, 0xFFFFFFFF); //variable framerate
avpriv_set_pts_info(s->streams[0], 32, 1, 1000);

@ -82,5 +82,8 @@
#ifndef FF_API_AV_GETTIME
#define FF_API_AV_GETTIME (LIBAVFORMAT_VERSION_MAJOR < 55)
#endif
#ifndef FF_API_R_FRAME_RATE
#define FF_API_R_FRAME_RATE (LIBAVFORMAT_VERSION_MAJOR < 55)
#endif
#endif /* AVFORMAT_VERSION_H */

Loading…
Cancel
Save