Вопрос

I have multiple recorded video samples, when I run these through my program it returns the FPS among other things. It is accurate enough for all of my video samples (see table below) but when I run a video sample taken through my smartphone it is returning the FPS at 90000, this happens with every video that captured through my smartphone so it is not just a problem with a single video file.

File              Actual FPS          OpenCV FPS          ffmpeg FPS

action-60fps         60                   59                  60


action-24fps         24                   24                  24


phone_panning        29                  90000                29

What is causing this problem?

EDIT: Managed to forget to add my code...

  VideoCapture capture(argv[1]);
  Mat frame;
  if(capture.isOpened()) {
    int fps = capture.get(CV_CAP_PROP_FPS);
    int width = capture.get(CV_CAP_PROP_FRAME_WIDTH);
    int height = capture.get(CV_CAP_PROP_FRAME_HEIGHT);
    cout << "FPS: " << fps << ", width: " << width << ", height: " << height << endl;
    VideoWriter writer("output.mpg",
    CV_FOURCC('P','I','M','1'), fps, cvSize(width, height), 0); // 0 means gray, 1 means color
    if(writer.isOpened()) {
      while(true) {
        capture >> frame;
        if(!frame.empty()) {
          imshow("Video", frame);
        }
        Mat frame_gray = frame.clone();
        cvtColor(frame, frame_gray, CV_RGB2GRAY);
        writer << frame_gray;
        int key = waitKey(25);
        if((char)key == 'q') { 
          break; 
        }
      }
    }
  }
Это было полезно?

Решение

I had the same problem with opencv in calculating the FPS and number of frames in a video. (It was returning 90,000 for FPS and 5,758,245 for frame count for a 64-second video!!) According to this answer: OpenCV captures only a fraction of the frames from a video file it's an opencv issue and they are working on it.

Another reason could be a problem with file header, mine was caused by converting video format. I solved it by using original video format mp4, instead of avi.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top