Skip to content

FFmpeg videoio backend won't decode low fps videos on machines with lots of cpus #20002

@jcowgill

Description

@jcowgill
System information (version)
  • OpenCV => 4.5.2
  • Operating System / Platform => Ubuntu 18.04
  • Compiler => GCC 7.5
Detailed description

The attached test videos can't be decoded by VideoCapture using the FFmpeg backend in OpenCV (grab always returns false). They both play correctly with ffplay.

I generated both the videos by downloading Spring (https://www.youtube.com/watch?v=WhWc3b3KhnY - probably another video would work), then running these ffmpeg commands to reduce the framerate:

ffmpeg -ss 60 -t 100 -i Spring.mkv -codec:a copy -filter:v fps=10 -crf 30 test-10fps.mkv
ffmpeg -ss 60 -t 100 -i Spring.mkv -codec:a copy -filter:v fps=0.1 test-01fps.mkv

(-crf 30 is only there to not hit the upload size limit)

I have two test machines: a laptop and a big server.

  • On the first machine which has 8 logical cpus, the test-10fps.mkv video works, but the test-01fps.mkv video does not.
  • On the second machine which has 128 logical cpus both videos fail. If I offline 96 of the cpus (32 remaining, no code or any other changes) the test-10fps.mkv video starts working.

I also noticed that:

  • Removing the audio streams from either file makes them work correctly.
  • Sortening the file too much also makes them work.
Steps to reproduce
#include <opencv2/opencv.hpp>
#include <iostream>

int main(int argc, char**argv)
{
    auto x = cv::VideoCapture(argv[1], cv::CAP_FFMPEG);
    std::cout << (x.grab() ? "true" : "false") << std::endl;
    return 0;
}
$ g++ test.cpp -I /usr/local/include/opencv4/ -L /usr/local/lib/ -lopencv_videoio -lopencv_core
$ ./a.out test-1fps.mkv
false

Should print true.

Test files
test-10fps.mp4
test-01fps.mp4
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc
    (However I expect I could find a smaller reproducer if I tried very hard)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions