Ask Your Question
0

what should i do, to make videoWriter could record video per 30second

asked 2018-09-29 02:44:26 -0600

jian G gravatar image

updated 2018-09-29 03:31:06 -0600

berak gravatar image

hi,guy, i want to record a video per 30 seconds, but it's fail, only record about 14-16s video(about half time) how can i change my code, this is my code:

if liveWriter.isOpened() is False:  # record live video
    live_path = live_path + os.sep + str(recordTime).replace("-", "_").replace(" ", "_").replace(":", "_")\
                + '.avi'
    liveWriter.open(live_path, fourcc, int(cap.get(cv2.CAP_PROP_FPS)),
                    (int(frame.shape[1]), int(frame.shape[0])))
    livePathList.append(live_path)
liveWriter.write(frame)
if recordTime > live_range_end: # if now time is over the range_end time, start a new video
    live_range_start, live_range_end = mod.get_time_range(datetime.datetime.now(), interval_hour=0,
                                                          interval_minute=0, interval_second=30) # get the time range
    liveWriter.release()

by the way, i have 3 videoWriter in this .py file

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-09-29 03:43:42 -0600

berak gravatar image

updated 2018-09-29 03:52:12 -0600

you should not rely on cap.get(cv2.CAP_PROP_FPS), it might be entirely bogus, and never takes into account, how much time is actually spent in your frame loop.

you have to measure your actual fps, and put that into your VideoWriter. then you have to calculate "how many frames go into 30 seconds, and count them in your program

then, all you have to control the playrate is minimizing the overall workload (3 videowriters ? bad idea !) and carefully throtteling with the sleep time in waitKey()

last but not least: those classes are utility functions to acquire images easily for computer-vision . don't try to abuse those for video editing, etc. if you need a time-exact recording software, use vlc,ffmpeg,gstreamer, not opencv.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-09-29 02:44:26 -0600

Seen: 734 times

Last updated: Sep 29 '18