I encountered a issue of high memory usage when writing too many frames using FFmpeg as the API Backend for OpenCV 4.7 VideoWriter on Linux, The pseudo code is as follows:
cv::VideoWriter writer(video_path, video_fourcc, video_fps, video_size);
int32_t frame_nums = 10000;
for (int32_t i = 0; i < frame_nums; ++i) {
cv::Mat frame;
// some operations
// ...
writer.write(frame);
frame.release();
}
writer.release();
As the number of frames written increases, the memory usage becomes larger and larger, and I can not reduce the memory usage.
I try to release the frame after writing it but it does not work, and I do not find anything like flush or any way to set the buffer size of VideoWriter.
How to solve it?