OpenCV how to interrupt video record with thread

asked Jul 23 '18

whdt gravatar image

updated Jul 30 '18

Eduardo gravatar image

Hi everyone: i facing a problem on interrupt video while hit timestamp. with the following code below it only generate 1 second video per time. i want to make it generate the video by 30 seconds every time. please help me thank you.

for (int ix = 30; ix >= 0 ; --ix)
{
   if (!cap.read(Source))
    {
       cerr << "ERROR! blank frame grabbed\n";
       break;
     }

     vWrite.write(Source);
}
Preview: (hide)

Comments

for (int ix = 900; ix >= 0 ; --ix)

LBerger gravatar imageLBerger (Jul 23 '18)edit

thanks for quick response, how to make it exactly 30 seconds , it finish recording video at 45 seconds.

whdt gravatar imagewhdt (Jul 24 '18)edit

is it a way using lamba to do it?

thread timer([] () {
   this_thread::sleep_for(chrono::seconds(30));
   vwrite.write(Source);
});

i have try the code above but it don't seen like working properly because i already have a thread running for capture stream to avoid the stream disconnected and reconnect back.

whdt gravatar imagewhdt (Jul 24 '18)edit

You have to use a timer. Now recording a video 30 swith frame rate equal to 30 you will need 900 images. Video time is not always real time

LBerger gravatar imageLBerger (Jul 24 '18)edit

is it possible to make it real time? i test it in 1 minutes it records for 1 minutes 45 seconds.

whdt gravatar imagewhdt (Jul 24 '18)edit

You will need to grab 30 frame per second then you have to check time in grab loop : grab frame at t=0 , 1/30, 2/30... and 899/30

LBerger gravatar imageLBerger (Jul 24 '18)edit

i have use the code below to check the frame

capture.get(CV_CAP_PROP_POS_FRAMES)

it will show totally frame in loop grab per time start from 0 to 29 frames. sorry i don't understand how to grab frame at t = 0, 1/30, 2/30.....and 899/30 can you give me an example? thank you.

whdt gravatar imagewhdt (Jul 24 '18)edit

In cap.read(Source) what is source ? a video file ? a webcam ?

LBerger gravatar imageLBerger (Jul 24 '18)edit

source = get stream from webcam

whdt gravatar imagewhdt (Jul 24 '18)edit

You have to check time if it is a webcam

LBerger gravatar imageLBerger (Jul 24 '18)edit