summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2012-06-26 13:10:01 +0200
committerAnton Khirnov <anton@khirnov.net>2012-07-29 08:06:30 +0200
commitaba232cfa9b193604ed98f3fa505378d006b1b3b (patch)
tree853cfd07d72dc8b0fa63ee1a7bc76e335321f845 /libavformat
parentf66eeff1c8fc5c1b2e5a563cf336865d52329006 (diff)
lavf: deprecate r_frame_rate.
According to its description, it is supposed to be the LCM of all the frame durations. The usability of such a thing is vanishingly small, especially since we cannot determine it with any amount of reliability. Therefore get rid of it after the next bump. Replace it with the average framerate where it makes sense. FATE results for the wtv and xmv demux tests change. In the wtv case this is caused by the file being corrupted (or possibly badly cut) and containing invalid timestamps. This results in lavf estimating the framerate wrong and making up wrong frame durations. In the xmv case the file contains pts jumps, so again the estimated framerate is far from anything sane and lavf again makes up different frame durations. In some other tests lavf starts making up frame durations from different frame.
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/avformat.h4
-rw-r--r--libavformat/avisynth.c7
-rw-r--r--libavformat/avs.c6
-rw-r--r--libavformat/electronicarts.c6
-rw-r--r--libavformat/flvenc.c6
-rw-r--r--libavformat/matroskadec.c6
-rw-r--r--libavformat/mov.c2
-rw-r--r--libavformat/nuv.c5
-rw-r--r--libavformat/r3d.c22
-rw-r--r--libavformat/rawdec.c5
-rw-r--r--libavformat/rmdec.c6
-rw-r--r--libavformat/utils.c18
-rw-r--r--libavformat/vc1testenc.c4
-rw-r--r--libavformat/version.h3
14 files changed, 69 insertions, 31 deletions
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 0e50487414..1dbbb10338 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -630,6 +630,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
@@ -639,6 +640,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;
/**
@@ -714,10 +716,12 @@ typedef struct AVStream {
*/
#define MAX_STD_TIMEBASES (60*12+5)
struct {
+#if FF_API_R_FRAME_RATE
int64_t last_dts;
int64_t duration_gcd;
int duration_count;
double duration_error[MAX_STD_TIMEBASES];
+#endif
int nb_decoded_frames;
int found_decoder;
diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index c4c523dc8a..d31c427646 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -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;
diff --git a/libavformat/avs.c b/libavformat/avs.c
index 7542ca7a9a..a03f7e336a 100644
--- a/libavformat/avs.c
+++ b/libavformat/avs.c
@@ -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);
diff --git a/libavformat/electronicarts.c b/libavformat/electronicarts.c
index b215547f33..cc51af6e61 100644
--- a/libavformat/electronicarts.c
+++ b/libavformat/electronicarts.c
@@ -432,8 +432,10 @@ static int ea_read_header(AVFormatContext *s)
st->codec->width = ea->width;
st->codec->height = ea->height;
avpriv_set_pts_info(st, 33, 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};
+#if FF_API_R_FRAME_RATE
+ st->r_frame_rate =
+#endif
+ st->avg_frame_rate = (AVRational){ea->time_base.den, ea->time_base.num};
}
if (ea->audio_codec) {
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index ce1a4e45cc..2222085470 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -202,9 +202,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);
}
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index c454713eeb..da86ed343e 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -1594,9 +1594,11 @@ static int matroska_read_header(AVFormatContext *s)
if (st->codec->codec_id != CODEC_ID_H264)
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
}
} else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 59d7b1a7e4..95acccfc7a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1984,9 +1984,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) {
diff --git a/libavformat/nuv.c b/libavformat/nuv.c
index c1dc07f18f..3939828ffb 100644
--- a/libavformat/nuv.c
+++ b/libavformat/nuv.c
@@ -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;
diff --git a/libavformat/r3d.c b/libavformat/r3d.c
index f67d10eb80..1795631bea 100644
--- a/libavformat/r3d.c
+++ b/libavformat/r3d.c
@@ -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);
diff --git a/libavformat/rawdec.c b/libavformat/rawdec.c
index 1ef780b952..d81fa42d34 100644
--- a/libavformat/rawdec.c
+++ b/libavformat/rawdec.c
@@ -158,7 +158,10 @@ int ff_raw_video_read_header(AVFormatContext *s)
goto fail;
}
- st->r_frame_rate = st->avg_frame_rate = framerate;
+#if FF_API_R_FRAME_RATE
+ st->r_frame_rate =
+#endif
+ st->avg_frame_rate = framerate;
avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
fail:
diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 0113251bc6..05a7c59f45 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -344,9 +344,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:
diff --git a/libavformat/utils.c b/libavformat/utils.c
index d358c324f8..3630c6f93f 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -758,9 +758,9 @@ static void compute_frame_duration(int *pnum, int *pden, AVStream *st,
*pden = 0;
switch(st->codec->codec_type) {
case AVMEDIA_TYPE_VIDEO:
- if (st->r_frame_rate.num) {
- *pnum = st->r_frame_rate.den;
- *pden = st->r_frame_rate.num;
+ if (st->avg_frame_rate.num) {
+ *pnum = st->avg_frame_rate.den;
+ *pden = st->avg_frame_rate.num;
} else if(st->time_base.num*1000LL > st->time_base.den) {
*pnum = st->time_base.num;
*pden = st->time_base.den;
@@ -2287,7 +2287,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;
}
@@ -2316,8 +2318,8 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
if (ic->fps_probe_size >= 0)
fps_analyze_framecount = ic->fps_probe_size;
/* variable fps and no guess at the real fps */
- if( tb_unreliable(st->codec) && !(st->r_frame_rate.num && st->avg_frame_rate.num)
- && st->info->duration_count < fps_analyze_framecount
+ if( tb_unreliable(st->codec) && !st->avg_frame_rate.num
+ && st->codec_info_nb_frames < fps_analyze_framecount
&& st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
break;
if(st->parser && st->parser->parser->split && !st->codec->extradata)
@@ -2423,6 +2425,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
break;
}
}
+#if FF_API_R_FRAME_RATE
{
int64_t last = st->info->last_dts;
@@ -2446,6 +2449,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) {
@@ -2508,6 +2512,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
best_fps, 12*1001, INT_MAX);
}
}
+#if FF_API_R_FRAME_RATE
// 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.
// ipmovie.c produces.
@@ -2530,6 +2535,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
if (num && (!st->r_frame_rate.num || (double)num/(12*1001) < 1.01 * av_q2d(st->r_frame_rate)))
av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX);
}
+#endif
}else if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
if(!st->codec->bits_per_coded_sample)
st->codec->bits_per_coded_sample= av_get_bits_per_sample(st->codec->codec_id);
@@ -3343,8 +3349,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)
diff --git a/libavformat/vc1testenc.c b/libavformat/vc1testenc.c
index a1228d8d70..9c4eea2701 100644
--- a/libavformat/vc1testenc.c
+++ b/libavformat/vc1testenc.c
@@ -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);
diff --git a/libavformat/version.h b/libavformat/version.h
index 6b7ada8496..6a11bf9df7 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -64,5 +64,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 */