# VideoCapture stutters when I use cap.set

**URL:** <https://forum.opencv.org/t/videocapture-stutters-when-i-use-cap-set/2435>\
**Category:** Uncategorized\
**Created:** [March 28, 2021, 2:27pm UTC](https://forum.opencv.org/t/videocapture-stutters-when-i-use-cap-set/2435 "2021-03-28T14:27:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AchimMeyer](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@AchimMeyer](https://forum.opencv.org/u/AchimMeyer)\
**Post date:** [March 28, 2021, 2:27pm UTC](https://forum.opencv.org/t/videocapture-stutters-when-i-use-cap-set/2435/1 "2021-03-28T14:27:30Z")

</div>

Hello,  
I’m a beginner in programming and bad at English. But I hope that you will help me with my problem.

I open a video in my program and play it in a window.  
A video camera is also running, which I evaluate.  
If I don’t want to play the video from the beginning, it stutters (activate \*\*\*\*\*\*\*\*\*\*).  
Later I would like to repeat the last 3 seconds of the video during an action from the camera. Then I want to repeat the last three seconds again in slow motion.

I hope I have explained this clearly and you can help me.

(I use Rasbian on a Raspberry Pi 4b / 8Gb)

Many Thanks,

Achim

> ```
> #include <iostream>
> #include <opencv2/opencv.hpp>
> #include "opencv2/highgui/highgui.hpp"
> 
> using namespace cv;
> using namespace std;
> 
> //int zaehler= 200; // ****************************************** Begin at frame 200
> 
> int main()
> {
> VideoCapture capCam = VideoCapture(0); 
> VideoCapture capVid = VideoCapture("SW-3.mpeg");
> namedWindow("video", WINDOW_NORMAL);
> resizeWindow("video", 1300,700);
> moveWindow("video", 1950,0);
> while(waitKey(1) !='q')
> {
> Mat BildVid;
> Mat BildCam;
> Mat bgr[3];
> double min_val, max_val;
> Point minLoc, maxLoc;
> //double scalar;
> 
> capCam.read(BildCam);
> //capVid.set(1,zaehler);// ****************************
> //zaehler++;// **********************************
> capVid.read(BildVid);
> if(!BildCam.empty())
> {
> split(BildCam, bgr);
> //imshow(image, bgr[2]);
> //cvtColor(image, gray, COLOR_BGR2GRAY);
> 
> minMaxLoc( bgr[2], &min_val, &max_val, &minLoc, &maxLoc);
> if(max_val>250)
> {
> std::cout<<"maxLoc, maxVal = "<<maxLoc<<", "<<max_val<<std::endl;
> 
> circle (BildVid, maxLoc, 5, Scalar(0, 0, 255), 3, LINE_AA);
> }
> imshow("video", BildVid);
> //imshow("camera", BildCam);
> }
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [March 28, 2021, 3:23pm UTC](https://forum.opencv.org/t/videocapture-stutters-when-i-use-cap-set/2435/2 "2021-03-28T15:23:22Z")

</div>

> [@AchimMeyer](#):
>
> `capVid.set(1,zaehler);`

use [cv::CAP\_PROP\_POS\_FRAMES](https://docs.opencv.org/master/d4/d15/group __videoio__ flags__base.html#ggaeb8dd9c89c10a5c63c139bf7c4f5704da6223452891755166a4fd5173ea257068) instead of `1`

this would “seek”. that’s an expensive and complex operation in general, and it isn’t always precise.

I would recommend doing that _once_, and then simply read.

---

<div class="post-metadata">

**Author:** ![AchimMeyer](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@AchimMeyer](https://forum.opencv.org/u/AchimMeyer)\
**Post date:** [March 29, 2021, 7:02am UTC](https://forum.opencv.org/t/videocapture-stutters-when-i-use-cap-set/2435/3 "2021-03-29T07:02:59Z")

</div>

Outstanding! It works now!

Many Thanks
