Slow video write

asked 2018-01-16 20:39:10 -0500

updated 2018-01-17 02:45:28 -0500


I have a very simple program where I iterate over a video frame by frame and draw a circle at a (x,y) coordinate and create a new video. For a 6 second video this takes anywhere from 8-12 seconds. Can some one suggest some way to speed up this process?

Else, suggest if there are other libraries which can do this simple task faster than open cv? I want to process a 45 seconds video in under 4 seconds. I have an i7 processor and want to execute this code in windows 10 using c++. My video file is in .avi format.

VideoCapture inputVideo(source); 

VideoWriter outputVideo;

int ex = static_cast<int>(inputVideo.get(CAP_PROP_FOURCC));, ex, inputVideo.get(CAP_PROP_FPS), S, true);

Mat src;

for (;;) //Show the image captured in the window and repeat


        inputVideo >> src;              // read

        if (src.empty()) break;         // check if at end

        if (Ctr_vid > escape_frame - 1)

            circle(src, Point(x_List[Ctr_frame], y_List[Ctr_frame]), 20, Scalar(150, 150, 150), 5, 8);
        outputVideo << src;
edit retag flag offensive close merge delete


I want to process a 45 seconds video in under 4 seconds wait wut o_O your limiting factor here is not OpenCV but the video reader pipeline. What you are aiming for is simply not possible unless you first convert your video into frames and batch process those. But then again the conversion from video to frames and vice versa will be the bottleneck.

StevenPuttemans gravatar imageStevenPuttemans ( 2018-01-17 02:47:26 -0500 )edit