Mp4视频到JPG图片,MP4,转,jpg

发表时间:2020-12-25

import cv2

vc = cv2.VideoCapture("C:\\Users\\keying\\Desktop\\*.MP4")
c = 1
if vc.isOpened():
rval, frame = vc.read()
else:
rval = False
while rval:
rval, frame = vc.read()
cv2.imwrite('C:\\Users\\keying\\Desktop\\img\\2\\' + str(c) + '.jpg', frame)
c = c + 1
cv2.waitKey(1)
vc.release()

# def jpg2video(sp, fps):
#     """ 将图片合成视频. sp: 视频路径,fps: 帧率 """
#     fourcc = cv2.VideoWriter_fourcc(*"MJPG")
#     images = os.listdir('mv')
#     im = Image.open('mv/' + images[0])
#     vw = cv2.VideoWriter(sp, fourcc, fps, im.size)
#
#     os.chdir('mv')
#     for image in range(len(images)):
#         # Image.open(str(image)+'.jpg').convert("RGB").save(str(image)+'.jpg')
#         jpgfile = str(image + 1) + '.jpg'
#         try:
#             frame = cv2.imread(jpgfile)
#             vw.write(frame)
#         except Exception as exc:
#             print(jpgfile, exc)
#     vw.release()
#     print(sp, 'Synthetic success!')

文章来源互联网,如有侵权,请联系管理员删除。邮箱:417803890@qq.com / QQ:417803890

微配音

Python Free

邮箱:417803890@qq.com
QQ:417803890

皖ICP备19001818号
© 2019 copyright www.pythonf.cn - All rights reserved

微信扫一扫关注公众号:

联系方式

Python Free