From 02b398ef4957ec5d8278043218977a3ecccd9297 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sun, 13 Dec 2009 15:52:11 +0000 Subject: [PATCH] Add avg_frame_rate. Originally committed as revision 20826 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavformat/avformat.h | 5 +++++ libavformat/utils.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 507a491104..b67a1b4f6e 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -466,6 +466,11 @@ typedef struct AVStream { * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav* */ struct AVPacketList *last_in_packet_buffer; + + /** + * Average framerate + */ + AVRational avg_frame_rate; } AVStream; #define AV_PROGRAM_RUNNING 1 diff --git a/libavformat/utils.c b/libavformat/utils.c index 98f391658a..d55b0c52ce 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2223,6 +2223,10 @@ int av_find_stream_info(AVFormatContext *ic) } for(i=0;inb_streams;i++) { st = ic->streams[i]; + if(codec_info_nb_frames[i]>2) + av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den, + (codec_info_nb_frames[i]-2)*(int64_t)st->time_base.den, + codec_info_duration[i] *(int64_t)st->time_base.num, 60000); if (st->codec->codec_type == CODEC_TYPE_VIDEO) { if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_coded_sample) st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt); @@ -2900,6 +2904,8 @@ static void dump_stream_format(AVFormatContext *ic, int i, int index, int is_out display_aspect_ratio.num, display_aspect_ratio.den); } if(st->codec->codec_type == CODEC_TYPE_VIDEO){ + if(st->avg_frame_rate.den && st->avg_frame_rate.num) + print_fps(av_q2d(st->avg_frame_rate), "fps"); if(st->r_frame_rate.den && st->r_frame_rate.num) print_fps(av_q2d(st->r_frame_rate), "tbr"); if(st->time_base.den && st->time_base.num)