python opencv生成 html5 支援的mp4
阿新 • • 發佈:2018-12-10
opencv4.0
stream = cv2.VideoCapture(0)
建立ok:
fourcc = cv2.VideoWriter_fourcc(*'avc1')#7579
fourcc = cv2.VideoWriter_fourcc(*'H264') #7473
fourcc = cv2.VideoWriter_fourcc(*'x264')
有mp4,播不了:
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
data='123.mp4'
以前的程式碼:
#!/usr/local/bin/python3
import cv2
videoCapture = cv2.VideoCapture('test.avi')
# fourcc = cv2.VideoWriter_fourcc(*'mp4v')
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter('output.mp4', fourcc, 5.0, (1280, 720))
while(1):
ret, frame=videoCapture.read()
if frame is None:
break
out.write(frame) # Write out frame to video
cv2.imshow('video',frame)
if (cv2.waitKey(1) & 0xFF) == ord('q'): # Hit `q` to exit
break
# Release everything if job is finished
out.release()
cv2.destroyAllWindows()