I'm not able to write an mp4 video file with cv2 on Rpi4. All I'm getting in feedback is VIDIOC_DQBUF: Invalid argument
writer = cv2.VideoWriter('test.mp4', cv2.VideoWriter_fourcc(*'mp4v'), fps, (640, 480), True)
stream = cv2.VideoCapture(0)
ret, frame = stream.read()
while ret:
writer.write(frame)
cv2.imshow('Video', frame)
ret, frame = stream.read()
if cv2.waitKey(1) & 0xFF==27:
break
stream.release()
writer.release()
cv2.destroyAllWindows()
The video is displaying using cv2.imshow(frame), and the file is outputted, however no frames are actually written to it, so the video file appears corrupted.
I am assuming this is a codec error. I've tried displaying the codecs using fourcc=-1 in VideoWriter() though the other fourcc's I've tried didn't work either. Has anyone had success using opencv writing videos on rpi4?
I've tested your code and it worked well on my Raspberry Pi 4. I'm using the latest Raspberry Pi OS and OpenCV 4.3.0. I can also use avi codec:
If you cannot use both of them, try to make some updates for your rpi4.