How to obtain the actual fps of a movie?

#include <opencv2/highgui.hpp>

#include <opencv2/imgcodecs.hpp>

#include <opencv2/imgproc.hpp>

#include <iostream>

int main()

{

    const std::string path = "../resources/test_video.mp4";

    cv::VideoCapture cap(path);

    if (!cap.isOpened())

    {

        std::cout << "Video cannot be opened!" << std::endl;

        return -1;

    }

    const std::string wndName = "input";

    cv::Mat frame;

    int fps = 30; // this fps should be obtained from the metadata of the loaded movie.

    while (cv::waitKey(1000 / fps) != 27) // press ESC to close prematurely

    {

        cap.read(frame);

        if (frame.empty())

        {

            std::cout << "Found the end of video!" << std::endl;

            break;

        }

        cv::imshow(wndName, frame);

    }

    return 0;

}

https://docs.opencv.org/master/d4/d15/group__videoio__flags__base.html#gaeb8dd9c89c10a5c63c139bf7c4f5704d

Thank you very much! It works!