Does VideoWriter have a lower boundary to the FPS?

Sometimes the rate of the image sequence I acquire is lower than 1 FPS. OpenCV doesn’t throw any errors if I pass < 1.0 in the VideoWriter ctor, but it creates an empty file.

For my use, capping the FPS at 1 is acceptable, but I can’t find in the documentation that there are any limits to the FPS.

If I were to guess, I would guess that at some point the provided FPS value is cast to an int, so values < 1 are truncated to 0 and VideoWriter is trying to make a 0 FPS video.

what backend is used? try it with CAP_FFMPEG. that’s well supported and the source indicates careful handling of such numbers.

the built-in avi+mjpeg seems to round FPS in places, so that will probably not suit you.

if you request 1.5 fps, does a handy video player report 1.0 fps, 2.0 fps, or 1.5 fps?

What do you mean by backend in this case?
For this particular use case I’m using the C# wrapper with v3.4.3. The frames are not captured with OpenCV

I’d never though of checking the frame rate of the video files, but I see now that FPS are truncated (1.7 -> 1.0, 1.2 -> 1.0 and so on)

backend meaning apiPreference argument to VideoWriter constructor

please present your code. that information is vital to helping you. I hate having to guess when you can just show what you’re doing.

Ahh, I see. The apiPreference is not an available option in the C# wrapper.
As mentioned, this behavior is acceptable for this exact use case, but now I now what to look out for. Thanks for the insight.

Here’s a code-snippet if your still interested

var writer = null;

while (true)
{
    frame = GetNextFrame();
    if (frame == null)
        break;
    if (writer == null)
        writer = new VideoWriter("videoName.mp4", FourCC.H264, fps, new OpenCvSharp.Size(frame.cols, frame. rows));
    writer.Write(frame);
}


thanks. seeing that code confirms that you aren’t using the default/builtin .AVI file writer. that one rounds its FPS values. .mp4 requires OpenCV to use some library, which is often FFMPEG but I guess OpenCvSharp might prefer Windows media APIs (dshow/MSMF). I haven’t checked those backends’ code for FPS rounding issues.

since you’re using OpenCvSharp, consider contacting the developers of that wrapper. they should be the first contact for any issues.

I just did a quick test. CAP_FFMPEG and CAP_DSHOW manage to create an mp4 file with 1.7 fps, but CAP_MSMF does not, it rounds down to 1.0 fps.

OpenCvSharp does support the apiPreference argument:

http://shimat.github.io/opencvsharp/api/OpenCvSharp.VideoWriter.html#OpenCvSharp_VideoWriter__ctor_System_String_OpenCvSharp_VideoCaptureAPIs_OpenCvSharp_FourCC_System_Double_OpenCvSharp_Size_System_Boolean_

Thank you. This is very helpful