Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use video stream fps first in FFmpeg backend for VideoCapture #24492

Merged
merged 1 commit into from Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions modules/videoio/src/cap_ffmpeg_impl.hpp
Expand Up @@ -1877,23 +1877,24 @@ int64_t CvCapture_FFMPEG::get_bitrate() const

double CvCapture_FFMPEG::get_fps() const
{
#if 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) || LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(52, 111, 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 LIBAVFORMAT_BUILD >= CALC_FFMPEG_VERSION(55, 1, 100) && LIBAVFORMAT_VERSION_MICRO >= 100
if (fps < eps_zero)
{
fps = r2d(ic->streams[video_stream]->avg_frame_rate);
fps = r2d(av_guess_frame_rate(ic, ic->streams[video_stream], NULL));
}
#endif

if (fps < eps_zero)
{
fps = 1.0 / r2d(ic->streams[video_stream]->time_base);
}
#endif

return fps;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/videoio/test/test_ffmpeg.cpp
Expand Up @@ -296,7 +296,7 @@ TEST_P(videoio_encapsulate, write)
ASSERT_TRUE(capActualRaw.isOpened());
const double fpsReference = capReference.get(CAP_PROP_FPS);
const double fpsActual = capActual.get(CAP_PROP_FPS);
ASSERT_EQ(fpsReference, fpsActual);
ASSERT_NEAR(fpsReference, fpsActual, 1e-2);
const int nFramesActual = static_cast<int>(capActual.get(CAP_PROP_FRAME_COUNT));
ASSERT_EQ(nFrames, nFramesActual);

Expand Down