1.python opencv 视频转图片
import cv2
vc=cv2.VideoCapture("video_path")
c=1
if vc.isOpened():
rval,frame=vc.read()
else:
rval=False
while rval:
rval,frame=vc.read()
cv2.imwrite('save_image_path/'+str(c)+'.jpg',frame)
c=c+1
cv2.waitKey(1)
vc.release()
2.图片转视频
import cv2
import os
fps = 30 #采用的帧率为30帧/秒
fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
video_writer = cv2.VideoWriter(filename='./result.avi', fourcc=fourcc, fps=fps, frameSize=(1920, 1080))
for i in range(0,6000):
p = i
if os.path.exists('/home//image//'+str(p)+'.jpg'): #判断图片是否存在
img = cv2.imread(filename='/home/hqd/image//'+str(p)+'.jpg')
cv2.waitKey(100)
video_writer.write(img)
print(str(p) + '.jpg' + ' done!')
video_writer.release()