Python OpenCV Opening Vid File vs. Opening Webcam -
i cant figure out why not working.
the following code works using webcam:
import numpy np import cv2 cap = cv2.videocapture(0) # define codec , create videowriter object fourcc = cv2.videowriter_fourcc(*'xvid') out = cv2.videowriter('output.avi',fourcc, 20.0, (640,480)) while(cap.isopened()): ret, frame = cap.read() if ret==true: frame = cv2.flip(frame,0) # write flipped frame out.write(frame) cv2.imshow('frame',frame) if cv2.waitkey(1) & 0xff == ord('q'): break else: break # release if job finished cap.release() out.release() cv2.destroyallwindows()
yet when exchange webcam video file, output not generate video. 5.7kb file named output.avi:
import numpy np import cv2 cap = cv2.videocapture('input.avi') # define codec , create videowriter object fourcc = cv2.videowriter_fourcc(*'xvid') out = cv2.videowriter('output.avi',fourcc, 20.0, (640,480)) while(cap.isopened()): ret, frame = cap.read() if ret==true: frame = cv2.flip(frame,0) # write flipped frame out.write(frame) cv2.imshow('frame',frame) if cv2.waitkey(1) & 0xff == ord('q'): break else: break # release if job finished cap.release() out.release() cv2.destroyallwindows()
i can see in windows video being processed not being saved. have tried changing resolution match initial video file.
i'm using opencv on ubuntu, , worked me:
out = cv2.videowriter("output.avi", cv.cv_fourcc(*'divx'), fps, (640, 480))
see if works on windows.
Comments
Post a Comment