diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-07-30 00:56:33 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-07-30 00:56:33 +0200 |
commit | 7d1918affee4bc70fb8ac139ba9235e7fed2979b (patch) | |
tree | b8c1beadf98aceeee6a155ae83bfc110656ca595 /libavformat | |
parent | 316f6df9cc5a70c5b117793c9f167c4ce629c1e0 (diff) | |
parent | 41f43202cf7648522b4ce0ed7bbb326655dbb9bc (diff) | |
download | ffmpeg-7d1918affee4bc70fb8ac139ba9235e7fed2979b.tar.gz |
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>
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/avformat.h | 2 | ||||
-rw-r--r-- | libavformat/avisynth.c | 7 | ||||
-rw-r--r-- | libavformat/avs.c | 6 | ||||
-rw-r--r-- | libavformat/electronicarts.c | 4 | ||||
-rw-r--r-- | libavformat/flvdec.c | 14 | ||||
-rw-r--r-- | libavformat/flvenc.c | 6 | ||||
-rw-r--r-- | libavformat/matroskadec.c | 6 | ||||
-rw-r--r-- | libavformat/mov.c | 2 | ||||
-rw-r--r-- | libavformat/nuv.c | 5 | ||||
-rw-r--r-- | libavformat/r3d.c | 22 | ||||
-rw-r--r-- | libavformat/rmdec.c | 6 | ||||
-rw-r--r-- | libavformat/utils.c | 25 | ||||
-rw-r--r-- | libavformat/vc1testenc.c | 4 | ||||
-rw-r--r-- | libavformat/version.h | 3 |
14 files changed, 80 insertions, 32 deletions
diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 19a11fc627..1614646aa5 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -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; /** diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c index edde77843b..dcfaa27033 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 8f3dd27dae..7bd4bcf82c 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 3070b05780..d6dfd92f2f 100644 --- a/libavformat/electronicarts.c +++ b/libavformat/electronicarts.c @@ -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) { diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 997824dcec..f8c25d36c1 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -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); diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 610c3fc720..c6a676a2db 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -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); } diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index bb61042775..8640aeeee0 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -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 */ diff --git a/libavformat/mov.c b/libavformat/mov.c index 1646c6330c..98e88af70e 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -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) { diff --git a/libavformat/nuv.c b/libavformat/nuv.c index e48c85a789..928f856c88 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 757e583213..4c32d90af5 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/rmdec.c b/libavformat/rmdec.c index 76b3bdfb62..24d80c820c 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -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: diff --git a/libavformat/utils.c b/libavformat/utils.c index d1e6459def..3807954e21 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -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) diff --git a/libavformat/vc1testenc.c b/libavformat/vc1testenc.c index 10b7b64819..56c723c729 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 d7841f743c..faf068ff39 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -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 */ |