OpenCV how to interrupt video record with thread

asked 2018-07-23 04:33:03 -0600

whdt gravatar image

updated 2018-07-30 06:32:53 -0600

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);
}
edit retag flag offensive close merge delete

Comments

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

LBerger gravatar imageLBerger ( 2018-07-23 04:51:29 -0600 )edit

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

whdt gravatar imagewhdt ( 2018-07-23 19:46:43 -0600 )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 ( 2018-07-23 20:00:09 -0600 )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 ( 2018-07-23 23:59:53 -0600 )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 ( 2018-07-24 00:04:41 -0600 )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 ( 2018-07-24 00:16:57 -0600 )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 ( 2018-07-24 00:51:27 -0600 )edit

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

LBerger gravatar imageLBerger ( 2018-07-24 01:51:26 -0600 )edit

source = get stream from webcam

whdt gravatar imagewhdt ( 2018-07-24 02:10:00 -0600 )edit

You have to check time if it is a webcam

LBerger gravatar imageLBerger ( 2018-07-24 02:32:04 -0600 )edit