使用opencv提取视频关键帧


 1 import cv2
 2 import sys
 3 
 4 path = 'D:\jiji_download\花花世界迷人眼❀波喵一花依世界'
 5 video_filename = '1.❀波喵❀(Av926216547,P1).mp4'
 6 vc = cv2.VideoCapture(path + '\\' + video_filename)
 7 
 8 ret_val = None
 9 if vc.isOpened():
10     ret_val = True
11     print("Open video succeed...")
12 else:
13     ret_val = False
14     print("Open video failed...")
15 
16 timeF = 200
17 c = 1
18 while ret_val:
19     ret_val, frame = vc.read()
20     if c % timeF == 0:
21         if not cv2.imwrite(path + '\\' + str(c) + '.jpg', frame):
22             print("Write image failed, please check the image path whether is ok...")
23             sys.exit(1)
24     c = c + 1
25 vc.release()

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM