cv2.VideoWriter always saves 5.55kb(5.5kb) video file (not working)
The reason why cv2.2VdeoWriter can't save the video content with correct code is the output video's width, height size is different with input video's width, height size.
You need to match them using below code.
import cv2 cap = cv2.VideoCapture('input.mp4')
vid_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) vid_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter('output.avi', fourcc, 20.0, (vid_width, vid_height))
while(cap.isOpened()): ret,frame = cap.read() if ret is False: break
# Image Processing
out.write(frame) cv2.imshow('frame', frame)
k = cv2.waitKey(50) & 0xff if k == 27: # Escape (ESC) break
cap.release() out.release() cv2.destroyAllWindows() |