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.
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: