From 6d54abbd0fc64b23ea0b97f3c906cba219b52dc8 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 1 Sep 2016 15:31:08 +0300 Subject: [PATCH 1/2] ffmpeg: fix get_fps() --- modules/videoio/src/cap_ffmpeg_impl.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/videoio/src/cap_ffmpeg_impl.hpp b/modules/videoio/src/cap_ffmpeg_impl.hpp index a0b9d402f6..9bc23bd965 100644 --- a/modules/videoio/src/cap_ffmpeg_impl.hpp +++ b/modules/videoio/src/cap_ffmpeg_impl.hpp @@ -1135,7 +1135,14 @@ int CvCapture_FFMPEG::get_bitrate() const double CvCapture_FFMPEG::get_fps() const { +#if 0 && LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(55, 1, 100) && LIBAVFORMAT_VERSION_MICRO >= 100 + double fps = r2d(av_guess_frame_rate(ic, ic->streams[video_stream], NULL)); +#else +#if LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(54, 1, 0) + double fps = r2d(ic->streams[video_stream]->avg_frame_rate); +#else double fps = r2d(ic->streams[video_stream]->r_frame_rate); +#endif #if LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 0) if (fps < eps_zero) @@ -1148,7 +1155,7 @@ double CvCapture_FFMPEG::get_fps() const { fps = 1.0 / r2d(ic->streams[video_stream]->codec->time_base); } - +#endif return fps; } From 03767340bb6de127b291e3b90978b5121d1982bc Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 8 Sep 2016 14:42:01 +0300 Subject: [PATCH 2/2] ffmpeg: fill avg_frame_rate --- modules/videoio/src/cap_ffmpeg_impl.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/videoio/src/cap_ffmpeg_impl.hpp b/modules/videoio/src/cap_ffmpeg_impl.hpp index 9bc23bd965..e7ece78a01 100644 --- a/modules/videoio/src/cap_ffmpeg_impl.hpp +++ b/modules/videoio/src/cap_ffmpeg_impl.hpp @@ -1582,6 +1582,10 @@ static AVStream *icv_add_video_stream_FFMPEG(AVFormatContext *oc, } #endif +#if LIBAVCODEC_BUILD >= CALC_FFMPEG_VERSION(52, 42, 0) + st->avg_frame_rate = (AVRational){frame_rate, frame_rate_base}; +#endif + return st; }