0

I want to record video with Raspberry Pi + wedcam (logitech). Although I found many examples which are actually almost the same code as following:

import numpy as np
import cv2

path = ('/.../output.avi')
fourcc = cv2.cv.CV_FOURCC(*'XVID')
out = cv2.VideoWriter(path,fourcc, 20.0, (640,480))

while(cap.isOpened()):
    #read the frame
    ret, frame = cap.read()
    if ret==True:
        #Write the frame
        video_writer.write(frame)
        #show the frame
        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# Release everything if job is finished
cap.release()
video_writer.release()
cv2.destroyAllWindows()

First question, I have tried all solutions from OpenCV write frame to file python but it seems those solutions didn't suitable for me... so I want to know if anyone has other solutions for this problem, I will appreciate! Second question, I found that someone use

cv2.VideoWriter_fourcc('XVID')

instead of

cv2.cv.CV_FOURCC(*'XVID')

Would that be the problem? Also, I have tried to use cv2.VideoWriter_fourcc('XVID'), but get an error: 'module' object has no attribute 'VideoWriter_fourcc'... How can I solve this? Thanks!

Edward Chang
  • 141
  • 1
  • 2
  • 11

1 Answers1

0

You used 'out' to create your video writer object

out = cv2.VideoWriter(path,fourcc, 20.0, (640,480))

So perhaps you should replace video_writer.write(frame) with out.write(frame)

Also replace video_writer.release() with out.release()

Patrick
  • 5,526
  • 14
  • 64
  • 101