First time here? Check out the FAQ!

Ask Your Question
0

cv2.VideoWriter.write is doing nothing

asked Jun 19 '13

harvey gravatar image

Hi, I am using python 2.7 with cv2 to record the video to file. My code is creating the file but its size is not updating it is always 0KB

Below is how I am trying

while myloop:

     sec = time.time()
     status,frame = cap.read()
     cv2.imshow("My Frame", frame)
     writer = cv2.VideoWriter(vidDir, fourcc, 30, (width,height))
     writer.write(frame)

it looks like cv2.VideoWriter.write is doing nothing. Can someone please help I want to capture the camera frames into a video file.

Thank you. harvey

Preview: (hide)

1 answer

Sort by » oldest newest most voted
0

answered Jun 19 '13

AMP gravatar image

You should write this part out of Loop

writer = cv2.VideoWriter(vidDir, fourcc, 30, (width,height))

because it construct a new video file at each iteration.

Preview: (hide)

Comments

oooh ofc. it's overwriting the thing in each frame ;)

berak gravatar imageberak (Jun 19 '13)edit

But still it is not writing to the file.

harvey gravatar imageharvey (Jun 19 '13)edit

Do I need to save and exit gracefully to save my frames to the video file, but the size of the video file is not changing even after writing writer = cv2.VideoWriter(vidDir, fourcc, 30, (width,height)) outside the loop

harvey gravatar imageharvey (Jun 19 '13)edit

Question Tools

Stats

Asked: Jun 19 '13

Seen: 2,120 times

Last updated: Jun 19 '13