python截取视频的某一帧,作为视频的预览图片
import cv2
def getVideoPng(_videoPath, _pngPath): # vidcap = cv2.VideoCapture("C:\\Users\\sswc\\Desktop\\gai2\\public\\showPdf\\6f3db1f9-e247-4aa5-bca7-93bae62a0079.mp4") vidcap = cv2.VideoCapture(_videoPath) success, image = vidcap.read() n = 1 while n < 30: success, image = vidcap.read() n += 1 # name = "C:\\Users\\sswc\\Desktop\\gai2\\public\\pdfImages\\6f3db1f9-e247-4aa5-bca7-93bae62a0079.png" # name = _pngPath imag = cv2.imwrite(_pngPath, image) if imag: print('ok') return 'ok' else: return 'failed'